nixos-config/config/apps/bash/nxr.sh

46 lines
765 B
Bash

# shellcheck disable=SC2148
function nxr() {
set -u
local pkg=""
local bin=""
local count=0
for var in "$@"; do
if [ "$var" == "--" ]; then
count=$((count + 1))
break
fi
if [ "$count" == "0" ]; then
pkg="$var"
fi
if [ "$count" == "1" ]; then
bin="$var"
fi
count=$((count + 1))
done
shift $count
if [ -z "$pkg" ]; then
echo "Error: no pkg name given"
exit 1
fi
if [ -z "$bin" ]; then
bin="$pkg"
fi
echo "Running nxr with:"
printf "\tpkg=%s" "$pkg"
printf "\tbin=%s" "$bin"
printf "\topts=%s" "$@"
printf "\n\n"
nix-shell -p "$pkg" --run "$bin $*"
set +u
}