mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-26 10:43:47 +08:00
fixup! Clean up completions a little bit
Reverts some changes that broke sudo completions, and adds comments clarifying the purpose behind sudo completions. Closes #5004.
This commit is contained in:
parent
6401906288
commit
46bd0e66b6
|
@ -1,29 +1,12 @@
|
|||
# Completions for the `apt` command
|
||||
|
||||
set -l all_subcmds update upgrade full-upgrade search list install show remove edit-sources purge changelog autoremove depends rdepends
|
||||
set -l pkg_subcmds install remove upgrade full-upgrade show search purge changelog policy depends rdepends
|
||||
|
||||
function __fish_apt_no_subcommand -d 'Test if apt has yet to be given the subcommand'
|
||||
for i in (commandline -opc)
|
||||
if contains -- $i update upgrade full-upgrade search list install show remove edit-sources purge changelog autoremove depends rdepends
|
||||
return 1
|
||||
end
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
function __fish_apt_subcommand
|
||||
set subcommand $argv[1]
|
||||
set -e argv[1]
|
||||
complete -f -c apt -n '__fish_apt_no_subcommand' -a $subcommand $argv
|
||||
end
|
||||
|
||||
function __fish_apt_using_subcommand -d 'Test if given subcommand is used'
|
||||
for i in (commandline -opc)
|
||||
if contains -- $i $argv
|
||||
return 0
|
||||
end
|
||||
end
|
||||
return 1
|
||||
complete -f -c apt -n "not __fish_seen_subcommand_from $all_subcmds" -a $subcommand $argv
|
||||
end
|
||||
|
||||
function __fish_apt_option
|
||||
|
@ -32,7 +15,7 @@ function __fish_apt_option
|
|||
complete -f -c apt -n "__fish_seen_subcommand_from $subcommand" $argv
|
||||
end
|
||||
|
||||
complete -c apt -n '__fish_seen_subcommand_from $pkg_subcmds' -a '(__fish_print_packages)' -d 'Package'
|
||||
complete -c apt -n "__fish_seen_subcommand_from $pkg_subcmds" -a '(__fish_print_packages | head -n 100)' -d 'Package'
|
||||
|
||||
# Support flags
|
||||
complete -x -f -c apt -s h -l help -d 'Display help'
|
||||
|
|
|
@ -23,6 +23,9 @@ complete -c sudo -s s -d "Run the given command in a shell"
|
|||
complete -c sudo -s u -a "(__fish_complete_users)" -x -d "Run command as user"
|
||||
complete -c sudo -s v -n "__fish_no_arguments" -d "Validate the credentials, extending timeout"
|
||||
|
||||
# Complete the command we are executed under sudo
|
||||
complete -c sudo -d "Command to run" -x -a "(__fish_complete_subcommand_root -u -g)"
|
||||
|
||||
# Or provide completions
|
||||
function __fish_complete_sudo_payload
|
||||
set -l tokens (commandline -co)
|
||||
|
@ -48,4 +51,5 @@ function __fish_complete_sudo_payload
|
|||
end
|
||||
end
|
||||
|
||||
# Provide completions for the command being sudo'd, as if `sudo` weren't in play
|
||||
complete -c sudo -xa '(__fish_complete_sudo_payload)'
|
||||
|
|
4
share/functions/__fish_complete_subcommand_root.fish
Normal file
4
share/functions/__fish_complete_subcommand_root.fish
Normal file
|
@ -0,0 +1,4 @@
|
|||
function __fish_complete_subcommand_root -d "Run the __fish_complete_subcommand function using a PATH containing /sbin and /usr/sbin"
|
||||
set -lx -p PATH /sbin /usr/sbin 2>/dev/null
|
||||
__fish_complete_subcommand $argv
|
||||
end
|
Loading…
Reference in New Issue
Block a user