diff --git a/share/config.fish b/share/config.fish index 622988f74..2b6e0fc3f 100644 --- a/share/config.fish +++ b/share/config.fish @@ -23,8 +23,15 @@ end # function __fish_default_command_not_found_handler printf "fish: Unknown command: %s\n" (string escape -- $argv[1]) >&2 + for file in $PATH/$argv[1] + if test -e $file -a ! -x $file + printf (_ "fish: %s exists but isn't executable\n") (string escape -- $file) >&2 + break + end + end end + if not status --is-interactive # Hook up the default as the command_not_found handler # if we are not interactive to avoid custom handlers. diff --git a/share/functions/fish_command_not_found.fish b/share/functions/fish_command_not_found.fish index b3dcd6fe7..d6fd6cdc6 100644 --- a/share/functions/fish_command_not_found.fish +++ b/share/functions/fish_command_not_found.fish @@ -13,6 +13,12 @@ end function __fish_default_command_not_found_handler printf "fish: Unknown command: %s\n" (string escape -- $argv[1]) >&2 + for file in $PATH/$argv[1] + if test -e $file -a ! -x $file + printf (_ "fish: %s exists but isn't executable\n") (string escape -- $file) >&2 + break + end + end end # If an old handler already exists, defer to that. diff --git a/tests/checks/command-not-found.fish b/tests/checks/command-not-found.fish index 128d3b94c..841f33c4a 100644 --- a/tests/checks/command-not-found.fish +++ b/tests/checks/command-not-found.fish @@ -32,4 +32,14 @@ echo $status # CHECKERR: { echo; echo } # CHECKERR: ^ +set -g PATH . +echo banana > foobar +foobar --banana +# CHECKERR: fish: Unknown command: foobar +# CHECKERR: fish: ./foobar exists but isn't executable +# CHECKERR: checks/command-not-found.fish (line 37): +# CHECKERR: foobar --banana +# CHECKERR: ^ + + exit 0