mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-14 22:14:53 +00:00
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:
parent
dc4e88d7b4
commit
71cfd25c1d
3 changed files with 23 additions and 0 deletions
|
@ -23,8 +23,15 @@ end
|
||||||
#
|
#
|
||||||
function __fish_default_command_not_found_handler
|
function __fish_default_command_not_found_handler
|
||||||
printf "fish: Unknown command: %s\n" (string escape -- $argv[1]) >&2
|
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
|
end
|
||||||
|
|
||||||
|
|
||||||
if not status --is-interactive
|
if not status --is-interactive
|
||||||
# Hook up the default as the command_not_found handler
|
# Hook up the default as the command_not_found handler
|
||||||
# if we are not interactive to avoid custom handlers.
|
# if we are not interactive to avoid custom handlers.
|
||||||
|
|
|
@ -13,6 +13,12 @@ end
|
||||||
|
|
||||||
function __fish_default_command_not_found_handler
|
function __fish_default_command_not_found_handler
|
||||||
printf "fish: Unknown command: %s\n" (string escape -- $argv[1]) >&2
|
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
|
end
|
||||||
|
|
||||||
# If an old handler already exists, defer to that.
|
# If an old handler already exists, defer to that.
|
||||||
|
|
|
@ -32,4 +32,14 @@ echo $status
|
||||||
# CHECKERR: { echo; echo }
|
# CHECKERR: { echo; echo }
|
||||||
# CHECKERR: ^
|
# 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
|
exit 0
|
||||||
|
|
Loading…
Reference in a new issue