mirror of
https://github.com/Swarsel/.dotfiles.git
synced 2025-12-06 09:07:21 +01:00
feat: add nix-index-database
This commit is contained in:
parent
6ea2eb0782
commit
193cf5748e
6 changed files with 196 additions and 41 deletions
33
scripts/command-not-found.sh
Normal file
33
scripts/command-not-found.sh
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
# Adapted from https://github.com/bennofs/nix-index/blob/master/command-not-found.sh
|
||||
|
||||
command_not_found_handle () {
|
||||
if [ -n "${MC_SID-}" ] || ! [ -t 1 ]; then
|
||||
>&2 echo "$1: command not found"
|
||||
return 127
|
||||
fi
|
||||
|
||||
echo -n "searching nix-index..."
|
||||
ATTRS=$(@nix-locate@ --minimal --no-group --type x --type s --top-level --whole-name --at-root "/bin/$1")
|
||||
|
||||
case `echo -n "$ATTRS" | grep -c "^"` in
|
||||
0)
|
||||
>&2 echo -ne "$(@tput@ el1)\r"
|
||||
>&2 echo "$1: command not found"
|
||||
;;
|
||||
*)
|
||||
>&2 echo -ne "$(@tput@ el1)\r"
|
||||
>&2 echo "The program ‘$(@tput@ setaf 4)$1$(@tput@ sgr0)’ is currently not installed."
|
||||
>&2 echo "It is provided by the following derivation(s):"
|
||||
while read ATTR; do
|
||||
ATTR=$(echo "$ATTR" | sed 's|\.out$||') # Strip trailing '.out'
|
||||
>&2 echo " $(@tput@ setaf 12)nixpkgs#$(@tput@ setaf 4)$ATTR$(@tput@ sgr0)"
|
||||
done <<< "$ATTRS"
|
||||
esac
|
||||
|
||||
return 127
|
||||
}
|
||||
|
||||
command_not_found_handler () {
|
||||
command_not_found_handle $@
|
||||
return $?
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue