fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Johannes AltmanningerFix double expansion of tokenized command line6b5ad163d

master
1.7 KiB36 linesraw
1# Completion for doas https://github.com/multiplexd/doas
2# based on the sudo completions
3#
4
5function __fish_doas_print_remaining_args
6    set -l tokens (commandline -xpc | string escape) (commandline -ct)
7    set -e tokens[1]
8    # These are all the options mentioned in the man page for openbsd's "doas" (in that order).
9    set -l opts a= C= L n s u=
10    argparse -s $opts -- $tokens 2>/dev/null
11    # The remaining argv is the subcommand with all its options, which is what
12    # we want.
13    if test -n "$argv"
14        and not string match -qr '^-' $argv[1]
15        string join0 -- $argv
16        return 0
17    else
18        return 1
19    end
20end
21
22function __fish_complete_doas_subcommand
23    set -l args (__fish_doas_print_remaining_args | string split0)
24    set -lx -a PATH /usr/local/sbin /sbin /usr/sbin
25    __fish_complete_subcommand --commandline $args
26end
27
28complete -c doas -n "not __fish_doas_print_remaining_args" -s a -d "Choose auth method on systems using /etc/login.conf"
29complete -c doas -n "not __fish_doas_print_remaining_args" -s C -r -d "validate given config file and test it against given command"
30complete -c doas -n "not __fish_doas_print_remaining_args" -s L -d "Clear persisted authorizations, then exit"
31complete -c doas -n "not __fish_doas_print_remaining_args" -s n -d "Fail if doas would prompt for password"
32complete -c doas -n "not __fish_doas_print_remaining_args" -s s -d "Execute the shell from SHELL or /etc/passwd"
33complete -c doas -n "not __fish_doas_print_remaining_args" -s u -a "(__fish_complete_users)" -x -d "Execute the command as user. The default is root."
34
35# Complete the command we are executing under doas
36complete -c doas -x -a "(__fish_complete_doas_subcommand)"