Command-not-found: Warn if a file exists but isn't executable

This simply adds a nice error so you can better see if your command
isn't available because it's not executable.

Fixes #8804.
This commit is contained in:
Fabian Homborg 2022-03-17 18:06:36 +01:00
parent dc4e88d7b4
commit 71cfd25c1d
3 changed files with 23 additions and 0 deletions

View file

@ -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.

View file

@ -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.

View file

@ -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