Debian Codegraph @

doc/examples/completion_parse_args

raw
1 # @mindmaze_header@
2 #
3 # vi:syntax=sh
4 #
5 # Example of bash completion script for mmlib based argument parsing (to be
6 # sourced)
7 #
8
9 _parse_args_completion() {
10 local cur=${COMP_WORDS[COMP_CWORD]}
11 local prev=${COMP_WORDS[COMP_CWORD-1]}
12
13 # If completion is done on empty word AND we are not completing long option
14 # value, then we invoked the command with an explicit "" final arg
15 # Without, the completion would have been done on previous arg
16 if [[ "$cur" == "" && "$prev" != "=" ]]; then
17 COMPREPLY=($(MMLIB_CMD_COMPLETION=yes $COMP_LINE "" 2>/dev/null))
18 else
19 COMPREPLY=($(MMLIB_CMD_COMPLETION=yes $COMP_LINE 2>/dev/null))
20 fi
21
22 # if there is only one possibility, do not add space if string finishes
23 # by '='. In such a case, we are completing the value of a long
24 # option... Same if it finishes with '/': we are completing a path
25 # Hence we test that number of elements in COMPREPLY is 1 and that the
26 # first element of COMPREPLY ends with '=' or '/'
27 if [[ ${#COMPREPLY[@]} -eq 1 && ${COMPREPLY[0]} == *[=/] ]]; then
28 compopt -o nospace
29 fi
30 }
31
32 complete -F _parse_args_completion parse_args