fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
a53db7256
master
1# localization: skip(private) 2function __fish_complete_subcommand -d"Complete subcommand" --no-scope-shadowing 3# How many non-option tokens we skip in the input commandline before completing the subcommand 4# Usually 1; use "--fcs-skip=2" to make it 2 (see e.g. tmux and ssh completions) 5set -l skip_next1 6set -l subcommand 7while string match -rq --'^--[a-z]' $argv [ 1 ] 8set -l arg$argv [ 1 ] 9set -e argv[ 1 ] 10switch $arg 11case '--fcs-skip=*' 12set skip_next( string split = --$arg )[ 2 ] 13case --commandline# --commandline means to use our arguments instead of the commandline. 14complete -C" $argv " 15return 16end 17end 18set -l options_with_param$argv 19 20set -l cmd( commandline -cxp| string escape) ( commandline -ct) 21while set -q cmd[ 1 ] 22set -l token$cmd [ 1 ] 23set -e cmd[ 1 ] 24if contains --$token $options_with_param 25set skip_next( math $skip_next +1 ) 26continue 27end 28switch $token 29case '-*' '*=*' 30continue 31case '*' 32if test $skip_next -gt 0 33set skip_next( math $skip_next -1 ) 34continue 35end 36# found the start of our command 37set subcommand$token $cmd 38break 39end 40end 41 42printf "%s\n" ( complete -C" $subcommand " ) 43end