From 46bd0e66b633b2e4f06564fa9ff288ac2df98e39 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Tue, 22 May 2018 17:29:12 -0500 Subject: [PATCH] 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. --- share/completions/apt.fish | 23 +++---------------- share/completions/sudo.fish | 4 ++++ .../__fish_complete_subcommand_root.fish | 4 ++++ 3 files changed, 11 insertions(+), 20 deletions(-) create mode 100644 share/functions/__fish_complete_subcommand_root.fish diff --git a/share/completions/apt.fish b/share/completions/apt.fish index 2173f46d7..239798430 100644 --- a/share/completions/apt.fish +++ b/share/completions/apt.fish @@ -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' diff --git a/share/completions/sudo.fish b/share/completions/sudo.fish index 705f17946..35b3c158a 100644 --- a/share/completions/sudo.fish +++ b/share/completions/sudo.fish @@ -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)' diff --git a/share/functions/__fish_complete_subcommand_root.fish b/share/functions/__fish_complete_subcommand_root.fish new file mode 100644 index 000000000..d434d0cbb --- /dev/null +++ b/share/functions/__fish_complete_subcommand_root.fish @@ -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