Skip to content

Instantly share code, notes, and snippets.

@pschyska
Last active March 4, 2021 11:58
Show Gist options
  • Save pschyska/884c9a8507c3f729eb0b6a58bf2ce1cf to your computer and use it in GitHub Desktop.
Save pschyska/884c9a8507c3f729eb0b6a58bf2ce1cf to your computer and use it in GitHub Desktop.
resolve executable in PATH to nix store
# $ q bash
# /nix/store/8wbyyhschvbg0r3p6lh6vpvys6zk4ivc-bash-interactive-4.4-p23/bin/bash
q() {
readlink -e "$(type -a -p "$@")"
}
# $ qr bash
# /nix/store/8wbyyhschvbg0r3p6lh6vpvys6zk4ivc-bash-interactive-4.4-p23
qr() {
recurse() {
local slashes="${1//[^\/]}"
if [[ "$1" =~ /^\/nix\/store ]] && [ ${#slashes} -gt 3 ]; then
recurse "$(dirname "$1")"
else
printf "%s\n" "$1"
fi
}
recurse "$(readlink -e "$(type -a -p "$1")")"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment