mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 05:13:10 +00:00
parent
ceade1629d
commit
4dc685db6b
1 changed files with 72 additions and 0 deletions
72
share/completions/argparse.fish
Normal file
72
share/completions/argparse.fish
Normal file
|
@ -0,0 +1,72 @@
|
|||
function __fish_argparse_exclusive_args --description 'Helper function to list unused options'
|
||||
set --local all_tokens (commandline --tokenize)
|
||||
set --erase all_tokens[1]
|
||||
set --local current_token (commandline --current-token)
|
||||
|
||||
if set --local index (contains --index -- '--' $all_tokens)
|
||||
set index (math $index - 1)
|
||||
else
|
||||
set index (count $all_tokens)
|
||||
end
|
||||
|
||||
set --local specifications
|
||||
while test $index -gt 0
|
||||
and set -l tok $all_tokens[$index]
|
||||
and not string match --quiet -- '-*' $tok
|
||||
|
||||
if string match --quiet '*,*' $tok
|
||||
set index (math $index - 1)
|
||||
continue
|
||||
end
|
||||
|
||||
set -l opt (string replace --regex '=.*' '' $tok)
|
||||
|
||||
if string match --quiet '*/*' $opt
|
||||
set --append specifications (string split '/' $opt)
|
||||
else if string match --quiet '*#*' $opt
|
||||
set --append specifications (string split '#' $opt)
|
||||
else
|
||||
set --append specifications $opt
|
||||
end
|
||||
set index (math $index - 1)
|
||||
end
|
||||
|
||||
if string match --quiet -- '-x*' $current_token
|
||||
set current_token (string replace --regex -- '^-x' '' $current_token)
|
||||
end
|
||||
|
||||
if test $index -gt 1
|
||||
and string match --regex --quiet -- '^(-x|--exclusive)$' $all_tokens[(math $index - 1)]
|
||||
and not test -z $current_token
|
||||
set --erase specifications[(count $specifications)]
|
||||
end
|
||||
|
||||
set --local used_options (string split -- ',' $current_token)
|
||||
set --local unused_specifications
|
||||
|
||||
for item in $specifications
|
||||
if not contains -- $item $used_options
|
||||
set --append unused_specifications $item
|
||||
end
|
||||
end
|
||||
|
||||
string join \n $unused_specifications
|
||||
end
|
||||
|
||||
complete --command argparse --no-files
|
||||
|
||||
complete --command argparse --short-option h --long-option help --description 'Show help'
|
||||
|
||||
complete --command argparse --short-option n --long-option name --require-parameter --no-files \
|
||||
--arguments '(functions --all | string replace ", " "\n")' --description 'Use function name'
|
||||
complete --command argparse --short-option x --long-option exclusive --no-files --require-parameter \
|
||||
--arguments '(__fish_append "," (__fish_argparse_exclusive_args))' \
|
||||
--description 'Specify mutually exclusive options'
|
||||
complete --command argparse --short-option N --long-option min-args --no-files --require-parameter \
|
||||
--description 'Specify minimum non-option argument count'
|
||||
complete --command argparse --short-option X --long-option max-args --no-files --require-parameter \
|
||||
--description 'Specify maximum non-option argument count'
|
||||
complete --command argparse --short-option i --long-option ignore-unknown \
|
||||
--description 'Ignore unknown options'
|
||||
complete --command argparse --short-option s --long-option stop-nonopt \
|
||||
--description 'Exit on subcommand'
|
Loading…
Reference in a new issue