completions: Stop checking for command existence

Since 4414d5c888 (in fish 3.0.0) we
don't autoload completions if the command doesn't exist.

So there is no need to check inside the scripts anymore.

Whats more, a few (like pip and cabal) checked `command -q` instead of
`type -q`, meaning they'd fail if someone used a function instead of a
command of that name.

If the *command* actually needs to exist, checks like that are still
warranted, like in `npm` where aliasing it to `nvm` is popular.

A teensy additional bit: Make `sysctl -w` the same as `sysctl
--write`. That description was bogus.
This commit is contained in:
Fabian Homborg 2020-05-18 20:10:03 +02:00
parent ec759fb45e
commit 43df5ba828
7 changed files with 74 additions and 89 deletions

View File

@ -1,12 +1,10 @@
function __fish_complete_cabal function __fish_complete_cabal
if type -q -f cabal
set -l cmd (commandline -poc) set -l cmd (commandline -poc)
if test (count $cmd) -gt 1 if test (count $cmd) -gt 1
cabal $cmd[2..-1] --list-options cabal $cmd[2..-1] --list-options
else else
cabal --list-options cabal --list-options
end end
end
end end
complete -c cabal -a '(__fish_complete_cabal)' complete -c cabal -a '(__fish_complete_cabal)'

View File

@ -1,4 +1 @@
if command -sq pip pip completion --fish 2>/dev/null | source
pip completion --fish 2>/dev/null | source
end

View File

@ -1,7 +1,5 @@
if command -sq pip2 # pip[2|3] emits (or emitted) completions with the wrong command name
# pip[2|3] emits (or emitted) completions with the wrong command name # See discussion at https://github.com/fish-shell/fish-shell/pull/4448
# See discussion at https://github.com/fish-shell/fish-shell/pull/4448 # and pip bug at https://github.com/pypa/pip/pull/4755
# and pip bug at https://github.com/pypa/pip/pull/4755 # Keep this even after pip fix is upstreamed for users not on the latest pip
# Keep this even after pip fix is upstreamed for users not on the latest pip pip2 completion --fish 2>/dev/null | string replace -r -- " -c\s+pip\b" " -c pip2" | source
pip2 completion --fish 2>/dev/null | string replace -r -- " -c\s+pip\b" " -c pip2" | source
end

View File

@ -1,7 +1,5 @@
if command -sq pip3 # pip[2|3] emits (or emitted) completions with the wrong command name
# pip[2|3] emits (or emitted) completions with the wrong command name # See discussion at https://github.com/fish-shell/fish-shell/pull/4448
# See discussion at https://github.com/fish-shell/fish-shell/pull/4448 # and pip bug at https://github.com/pypa/pip/pull/4755
# and pip bug at https://github.com/pypa/pip/pull/4755 # Keep this even after pip fix is upstreamed for users not on the latest pip
# Keep this even after pip fix is upstreamed for users not on the latest pip pip3 completion --fish 2>/dev/null | string replace -r -- " -c\s+pip\b" " -c pip3" | source
pip3 completion --fish 2>/dev/null | string replace -r -- " -c\s+pip\b" " -c pip3" | source
end

View File

@ -1,6 +1,5 @@
if type -q -f sysctl # Only GNU and BSD sysctl seem to know "-h", so others should exit non-zero
# Only GNU and BSD sysctl seem to know "-h", so others should exit non-zero if sysctl -h >/dev/null 2>/dev/null
if sysctl -h >/dev/null 2>/dev/null
# Print sysctl keys and values, separated by a tab # Print sysctl keys and values, separated by a tab
function __fish_sysctl_values function __fish_sysctl_values
sysctl -a 2>/dev/null | string replace -a " = " \t sysctl -a 2>/dev/null | string replace -a " = " \t
@ -8,12 +7,11 @@ if type -q -f sysctl
complete -c sysctl -a '(__fish_sysctl_values)' -f complete -c sysctl -a '(__fish_sysctl_values)' -f
complete -c sysctl -s w -d 'parameter to use.'
complete -c sysctl -s n -l values -d 'Only print values' complete -c sysctl -s n -l values -d 'Only print values'
complete -c sysctl -s e -l ignore -d 'Ignore errors about unknown keys' complete -c sysctl -s e -l ignore -d 'Ignore errors about unknown keys'
complete -c sysctl -s N -l names -d 'Only print names' complete -c sysctl -s N -l names -d 'Only print names'
complete -c sysctl -s q -l quiet -d 'Be quiet when setting values' complete -c sysctl -s q -l quiet -d 'Be quiet when setting values'
complete -c sysctl -l write -d 'Write value' complete -c sysctl -s w -l write -d 'Write value'
complete -c sysctl -o 'p[FILE]' -l 'load[' -d 'Load in sysctl settings from the file specified or /etc/sysctl' complete -c sysctl -o 'p[FILE]' -l 'load[' -d 'Load in sysctl settings from the file specified or /etc/sysctl'
complete -c sysctl -s a -l all -d 'Display all values currently available' complete -c sysctl -s a -l all -d 'Display all values currently available'
complete -c sysctl -l deprecated -d 'Include deprecated parameters too' complete -c sysctl -l deprecated -d 'Include deprecated parameters too'
@ -29,7 +27,7 @@ if type -q -f sysctl
# complete -c sysctl -s x -d 'Does nothing, exists for BSD compatibility' # complete -c sysctl -s x -d 'Does nothing, exists for BSD compatibility'
complete -c sysctl -s h -l help -d 'Display help text and exit.' complete -c sysctl -s h -l help -d 'Display help text and exit.'
complete -c sysctl -s V -l version -d 'Display version information and exit.' complete -c sysctl -s V -l version -d 'Display version information and exit.'
else else
# OSX sysctl # OSX sysctl
function __fish_sysctl_values function __fish_sysctl_values
sysctl -a 2>/dev/null | string replace -a ":" \t sysctl -a 2>/dev/null | string replace -a ":" \t
@ -42,5 +40,4 @@ if type -q -f sysctl
complete -c sysctl -s n -d 'Show only values, not names' complete -c sysctl -s n -d 'Show only values, not names'
complete -c sysctl -s w -d 'Set values' complete -c sysctl -s w -d 'Set values'
complete -c sysctl -s X -d 'Like -A, but prints a hex dump' complete -c sysctl -s X -d 'Like -A, but prints a hex dump'
end
end end

View File

@ -1,7 +1,7 @@
# Don't go invoking valgrind unless it is installed # Don't go invoking valgrind unless it is installed
set -l skin tool set -l skin tool
if type -q valgrind; and valgrind --version 2>/dev/null | string match -qr -- '-2\.[012]\.' if valgrind --version 2>/dev/null | string match -qr -- '-2\.[012]\.'
# In older versions of Valgrind, the skin selection option was # In older versions of Valgrind, the skin selection option was
# '--skin' # '--skin'
# But someone decided that it would be fun to change this to # But someone decided that it would be fun to change this to

View File

@ -3,12 +3,10 @@
# -wn : Set the default window size to n # -wn : Set the default window size to n
# +command : same as -c command # +command : same as -c command
# Check if vi exists at all ( needed for vi --version ) # Check if vi is really vim
if type -q vi if vi --version >/dev/null 2>/dev/null
# Check if vi is really vim
if vi --version >/dev/null 2>/dev/null
complete -c vi -w vim complete -c vi -w vim
else else
complete -c vi -s s -d 'Suppress all interactive user feedback' complete -c vi -s s -d 'Suppress all interactive user feedback'
complete -c vi -s C -d 'Encrypt/decrypt text' complete -c vi -s C -d 'Encrypt/decrypt text'
complete -c vi -s l -d 'Set up for editing LISP programs' complete -c vi -s l -d 'Set up for editing LISP programs'
@ -21,5 +19,4 @@ if type -q vi
complete -c vi -r -s r -d 'Recover file after crash' complete -c vi -r -s r -d 'Recover file after crash'
complete -c vi -r -s t -d 'Edit the file containing a tag' complete -c vi -r -s t -d 'Edit the file containing a tag'
complete -c vi -r -c t -d 'Begin editing by executing the specified editor command' complete -c vi -r -c t -d 'Begin editing by executing the specified editor command'
end
end end