fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
b78dc4fbe
master
1# localization: tier3 2function __fish_sudo_print_remaining_args 3set -l tokens( commandline -xpc| string escape) ( commandline -ct) 4set -e tokens[ 1 ] 5# These are all the options mentioned in the man page for Todd Miller's "sudo.ws" sudo (in that order). 6# If any other implementation has different options, this should be harmless, since they shouldn't be used anyway. 7set -l opts A/askpass b/background C/close-from= E/preserve-env='?' 8# Note that "-h" is both "--host" (which takes an option) and "--help" (which doesn't). 9# But `-h` as `--help` only counts when it's the only argument (`sudo -h`), 10# so any argument completion after that should take it as "--host". 11set -a opts e/edit g/group= H/set-home h/host= 1-help 12set -a opts i/login K/remove-timestamp k/reset-timestamp l/list n/non-interactive 13set -a opts P/preserve-groups p/prompt= S/stdin s/shell U/other-user= 14set -a opts u/user= T/command-timeout= V/version v/validate 15argparse -s$opts --$tokens 2> /dev/null 16# The remaining argv is the subcommand with all its options, which is what 17# we want. 18if test -n " $argv " 19and not string match -qr'^-' $argv [ 1 ] 20string join0 --$argv 21return 0 22else 23return 1 24end 25end 26 27function __fish_sudo_no_subcommand 28not __fish_sudo_print_remaining_args > /dev/null 29end 30 31function __fish_complete_sudo_subcommand 32set -l args( __fish_sudo_print_remaining_args | string split0) 33set -lx -a PATH /usr/local/sbin /sbin /usr/sbin 34__fish_complete_subcommand --commandline$args 35end 36 37function __fish_complete_sudo -a sudo 38# All these options should be valid for GNU and OSX sudo 39complete -c$sudo -n __fish_no_arguments -s h -d"Display help and exit" 40complete -c$sudo -n __fish_no_arguments -s V -d"Display version information and exit" 41complete -c$sudo -n __fish_sudo_no_subcommand -s A -d"Ask for password via the askpass or \$SSH_ASKPASS program" 42complete -c$sudo -n __fish_sudo_no_subcommand -s C -d"Close all file descriptors greater or equal to the given number" -xa"0 1 2 255" 43complete -c$sudo -n __fish_sudo_no_subcommand -s E -d"Preserve environment" 44complete -c$sudo -n __fish_sudo_no_subcommand -s H -d"Set home" 45complete -c$sudo -n __fish_sudo_no_subcommand -s K -d"Remove the credential timestamp entirely" 46complete -c$sudo -n __fish_sudo_no_subcommand -s P -d"Preserve group vector" 47complete -c$sudo -n __fish_sudo_no_subcommand -s S -d"Read password from stdin" 48complete -c$sudo -n __fish_sudo_no_subcommand -s b -d"Run command in the background" 49complete -c$sudo -n __fish_sudo_no_subcommand -s e -rF -d Edit 50complete -c$sudo -n __fish_sudo_no_subcommand -s g -a"(__fish_complete_groups)" -x -d"Run command as group" 51complete -c$sudo -n __fish_sudo_no_subcommand -s i -d"Run a login shell" 52complete -c$sudo -n __fish_sudo_no_subcommand -s k -d"Reset or ignore the credential timestamp" 53complete -c$sudo -n __fish_sudo_no_subcommand -s l -d"List the allowed and forbidden commands for the given user" 54complete -c$sudo -n __fish_sudo_no_subcommand -s n -d"Do not prompt for a password - if one is needed, fail" 55complete -c$sudo -n __fish_sudo_no_subcommand -s p -d"Specify a custom password prompt" 56complete -c$sudo -n __fish_sudo_no_subcommand -s s -d"Run the given command in a shell" 57complete -c$sudo -n __fish_sudo_no_subcommand -s u -a"(__fish_complete_users)" -x -d"Run command as user" 58complete -c$sudo -n __fish_sudo_no_subcommand -s v -n __fish_no_arguments -d"Validate the credentials, extending timeout" 59 60# Complete the command we are executed under sudo 61complete -c$sudo -x -n'not __fish_seen_argument -s e' -a"(__fish_complete_sudo_subcommand)" 62end