.dotfiles/pkgs/cnf/default.nix
2024-07-29 17:01:19 +02:00

40 lines
1.2 KiB
Nix
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{ writeShellApplication, ncurses, nix-index }:
writeShellApplication {
name = "cnf";
runtimeInputs = [ ncurses nix-index ];
text = ''
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 -r ATTR; do
ATTR=''${ATTR%.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 $?
}
'';
}