2021-05-13 09:52:50 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
print_err() {
|
|
|
|
printf "%s\n" "$1" >&2
|
|
|
|
}
|
|
|
|
|
|
|
|
usage() {
|
|
|
|
print_err "Usage: , <program> [argument]..."
|
|
|
|
}
|
|
|
|
|
|
|
|
find_program() {
|
|
|
|
local CANDIDATE
|
|
|
|
CANDIDATE="$(nix-locate --top-level --minimal --at-root --whole-name "/bin/$1")"
|
|
|
|
if [ "$(printf '%s\n' "$CANDIDATE" | wc -l)" -gt 1 ]; then
|
|
|
|
CANDIDATE="$(printf '%s' "$CANDIDATE" | fzf-tmux)"
|
|
|
|
fi
|
|
|
|
printf '%s' "$CANDIDATE"
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ $# -lt 1 ]; then
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
PROGRAM="$(find_program "$1")"
|
|
|
|
if [ -z "$PROGRAM" ]; then
|
|
|
|
print_err "No match found for $1"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-10-12 17:19:44 +02:00
|
|
|
nix shell "${COMMA_NIXPKGS_FLAKE:-nixpkgs}#$PROGRAM" -c "$@"
|