| read -ep "What command are you looking for?: " CMD |
| LOCATION=$(command -V "$CMD" 2>&1 | sed -rn "s/.* (.*)$/\1/p") |
| if [ "$LOCATION" = "found" ] # Not found |
| echo "The command $CMD wasn't found" |
| if [ "$LOCATION" = "builtin" ] # Shell builtin |
| echo "The command $CMD is a shell builtin" |
| RESOLVED_LOCATION=$(readlink -f "$LOCATION") |
| if [[ ! "$RESOLVED_LOCATION" =~ ^\/nix\/store\/.*-.*-.*$ ]]; |
| echo "The command $CMD is at $RESOLVED_LOCATION" |
| PACKAGE=$(echo "$RESOLVED_LOCATION" | sed -rn "s/\/nix\/store\/.*-(.*)-.*/\1/p") |
| SEARCHED=$(nix search "nixpkgs#$PACKAGE" 2>&1) |
| if [ "$SEARCHED" = "error: no results for the given search term(s)!" ] |
| echo "The command $CMD is at $RESOLVED_LOCATION" |
| echo "The command $CMD is from:" |
| echo "Which is available at $RESOLVED_LOCATION" |