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,11 +1,9 @@
function __fish_complete_cabal
if type -q -f cabal
set -l cmd (commandline -poc)
if test (count $cmd) -gt 1
cabal $cmd[2..-1] --list-options
else
cabal --list-options
end
set -l cmd (commandline -poc)
if test (count $cmd) -gt 1
cabal $cmd[2..-1] --list-options
else
cabal --list-options
end
end

View file

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

View file

@ -1,7 +1,5 @@
if command -sq pip2
# pip[2|3] emits (or emitted) completions with the wrong command name
# See discussion at https://github.com/fish-shell/fish-shell/pull/4448
# 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
pip2 completion --fish 2>/dev/null | string replace -r -- " -c\s+pip\b" " -c pip2" | source
end
# pip[2|3] emits (or emitted) completions with the wrong command name
# See discussion at https://github.com/fish-shell/fish-shell/pull/4448
# 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
pip2 completion --fish 2>/dev/null | string replace -r -- " -c\s+pip\b" " -c pip2" | source

View file

@ -1,7 +1,5 @@
if command -sq pip3
# pip[2|3] emits (or emitted) completions with the wrong command name
# See discussion at https://github.com/fish-shell/fish-shell/pull/4448
# 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
pip3 completion --fish 2>/dev/null | string replace -r -- " -c\s+pip\b" " -c pip3" | source
end
# pip[2|3] emits (or emitted) completions with the wrong command name
# See discussion at https://github.com/fish-shell/fish-shell/pull/4448
# 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
pip3 completion --fish 2>/dev/null | string replace -r -- " -c\s+pip\b" " -c pip3" | source

View file

@ -1,46 +1,43 @@
if type -q -f sysctl
# Only GNU and BSD sysctl seem to know "-h", so others should exit non-zero
if sysctl -h >/dev/null 2>/dev/null
# Print sysctl keys and values, separated by a tab
function __fish_sysctl_values
sysctl -a 2>/dev/null | string replace -a " = " \t
end
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 e -l ignore -d 'Ignore errors about unknown keys'
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 -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 -s a -l all -d 'Display all values currently available'
complete -c sysctl -l deprecated -d 'Include deprecated parameters too'
complete -c sysctl -s b -l binary -d 'Print value without new line'
complete -c sysctl -l system -d 'Load settings from all system configuration files'
complete -c sysctl -s r -l pattern -d 'Only apply settings that match pattern'
# Don't include these as they don't do anything
# complete -c sysctl -s A -d 'Alias of -a'
# complete -c sysctl -s d -d 'Alias of -h'
# complete -c sysctl -s f -d 'Alias of -p'
# complete -c sysctl -s X -d 'Alias of -a'
# complete -c sysctl -s o -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 V -l version -d 'Display version information and exit.'
else
# OSX sysctl
function __fish_sysctl_values
sysctl -a 2>/dev/null | string replace -a ":" \t
end
complete -c sysctl -a '(__fish_sysctl_values)' -f
complete -c sysctl -s a -d 'Display all non-opaque values currently available'
complete -c sysctl -s A -d 'Display all MIB variables'
complete -c sysctl -s b -d 'Output values in a binary format'
complete -c sysctl -s n -d 'Show only values, not names'
complete -c sysctl -s w -d 'Set values'
complete -c sysctl -s X -d 'Like -A, but prints a hex dump'
# Only GNU and BSD sysctl seem to know "-h", so others should exit non-zero
if sysctl -h >/dev/null 2>/dev/null
# Print sysctl keys and values, separated by a tab
function __fish_sysctl_values
sysctl -a 2>/dev/null | string replace -a " = " \t
end
complete -c sysctl -a '(__fish_sysctl_values)' -f
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 N -l names -d 'Only print names'
complete -c sysctl -s q -l quiet -d 'Be quiet when setting values'
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 -s a -l all -d 'Display all values currently available'
complete -c sysctl -l deprecated -d 'Include deprecated parameters too'
complete -c sysctl -s b -l binary -d 'Print value without new line'
complete -c sysctl -l system -d 'Load settings from all system configuration files'
complete -c sysctl -s r -l pattern -d 'Only apply settings that match pattern'
# Don't include these as they don't do anything
# complete -c sysctl -s A -d 'Alias of -a'
# complete -c sysctl -s d -d 'Alias of -h'
# complete -c sysctl -s f -d 'Alias of -p'
# complete -c sysctl -s X -d 'Alias of -a'
# complete -c sysctl -s o -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 V -l version -d 'Display version information and exit.'
else
# OSX sysctl
function __fish_sysctl_values
sysctl -a 2>/dev/null | string replace -a ":" \t
end
complete -c sysctl -a '(__fish_sysctl_values)' -f
complete -c sysctl -s a -d 'Display all non-opaque values currently available'
complete -c sysctl -s A -d 'Display all MIB variables'
complete -c sysctl -s b -d 'Output values in a binary format'
complete -c sysctl -s n -d 'Show only values, not names'
complete -c sysctl -s w -d 'Set values'
complete -c sysctl -s X -d 'Like -A, but prints a hex dump'
end

View file

@ -1,7 +1,7 @@
# Don't go invoking valgrind unless it is installed
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
# '--skin'
# But someone decided that it would be fun to change this to

View file

@ -3,23 +3,20 @@
# -wn : Set the default window size to n
# +command : same as -c command
# Check if vi exists at all ( needed for vi --version )
if type -q vi
# Check if vi is really vim
if vi --version >/dev/null 2>/dev/null
complete -c vi -w vim
else
complete -c vi -s s -d 'Suppress all interactive user feedback'
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 'List saved file names after crash'
complete -c vi -s R -d 'Read-only mode'
complete -c vi -s S -d 'Use linear search for tags if tag file not sorted'
complete -c vi -s v -d 'Start in display editing state'
complete -c vi -s V -d 'Verbose mode'
complete -c vi -s x -d 'Encrypt/decrypt text'
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 -c t -d 'Begin editing by executing the specified editor command'
end
# Check if vi is really vim
if vi --version >/dev/null 2>/dev/null
complete -c vi -w vim
else
complete -c vi -s s -d 'Suppress all interactive user feedback'
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 'List saved file names after crash'
complete -c vi -s R -d 'Read-only mode'
complete -c vi -s S -d 'Use linear search for tags if tag file not sorted'
complete -c vi -s v -d 'Start in display editing state'
complete -c vi -s V -d 'Verbose mode'
complete -c vi -s x -d 'Encrypt/decrypt text'
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 -c t -d 'Begin editing by executing the specified editor command'
end