···1122-22+- Improve bash completion of long options with `=` (#231).
33+ Thanks to Brian Ward for the patch.
34- Improve bash completion on files and directories (#238).
45 Thanks to Brian Ward for the report and fix.
56
+12-12
src/tool/bash-completion.sh
···11_cmdliner_generic() {
22- local prefix="${COMP_WORDS[COMP_CWORD]}"
33- local w=("${COMP_WORDS[@]}") # Keep COMP_WORDS intact for restart completion
44- w[COMP_CWORD]="--__complete=${COMP_WORDS[COMP_CWORD]}"
22+ local words cword
33+ # Equivalent of COMP_WORDS, COMP_CWORD but allow us to exclude '=' as a word separator
44+ _get_comp_words_by_ref -n = words cword
55+66+ local prefix="${words[cword]}"
77+ local w=("${words[@]}") # Keep words intact for restart completion
88+ w[cword]="--__complete=${words[cword]}"
59 local line="${w[@]:0:1} --__complete ${w[@]:1}"
610 local version type group item text_line item_doc msg
711 {
···4549 done
4650 # Sadly it seems bash does not support doc strings, so we only
4751 # add item to to the reply. If you know any better get in touch.
4848- # Handle glued forms, the completion item is the full option
4949- if [[ $group == "Values" ]]; then
5050- if [[ $prefix == --* ]]; then
5151- item="${prefix%%=*}=$item"
5252- elif [[ $prefix == -* ]]; then
5353- item="${prefix:0:2}$item"
5454- fi
5252+ if [[ $group == "Values" ]] && [[ $prefix == -* ]] && [[ $prefix != --* ]]; then
5353+ # properly complete short options
5454+ item="${prefix:0:2}$item"
5555 fi
5656 COMPREPLY+=($item)
5757 elif [[ $type == "restart" ]]; then
5858 # N.B. only emitted if there is a -- token
5959- for ((i = 0; i < ${#COMP_WORDS[@]}; i++)); do
6060- if [[ "${COMP_WORDS[i]}" == "--" ]]; then
5959+ for ((i = 0; i < ${#words[@]}; i++)); do
6060+ if [[ "${words[i]}" == "--" ]]; then
6161 _comp_command_offset $((i+1))
6262 return
6363 fi
+12-12
src/tool/cmdliner_data.ml
···11let bash_generic_completion =
22{|_cmdliner_generic() {
33- local prefix="${COMP_WORDS[COMP_CWORD]}"
44- local w=("${COMP_WORDS[@]}") # Keep COMP_WORDS intact for restart completion
55- w[COMP_CWORD]="--__complete=${COMP_WORDS[COMP_CWORD]}"
33+ local words cword
44+ # Equivalent of COMP_WORDS, COMP_CWORD but allow us to exclude '=' as a word separator
55+ _get_comp_words_by_ref -n = words cword
66+77+ local prefix="${words[cword]}"
88+ local w=("${words[@]}") # Keep words intact for restart completion
99+ w[cword]="--__complete=${words[cword]}"
610 local line="${w[@]:0:1} --__complete ${w[@]:1}"
711 local version type group item text_line item_doc msg
812 {
···4650 done
4751 # Sadly it seems bash does not support doc strings, so we only
4852 # add item to to the reply. If you know any better get in touch.
4949- # Handle glued forms, the completion item is the full option
5050- if [[ $group == "Values" ]]; then
5151- if [[ $prefix == --* ]]; then
5252- item="${prefix%%=*}=$item"
5353- elif [[ $prefix == -* ]]; then
5454- item="${prefix:0:2}$item"
5555- fi
5353+ if [[ $group == "Values" ]] && [[ $prefix == -* ]] && [[ $prefix != --* ]]; then
5454+ # properly complete short options
5555+ item="${prefix:0:2}$item"
5656 fi
5757 COMPREPLY+=($item)
5858 elif [[ $type == "restart" ]]; then
5959 # N.B. only emitted if there is a -- token
6060- for ((i = 0; i < ${#COMP_WORDS[@]}; i++)); do
6161- if [[ "${COMP_WORDS[i]}" == "--" ]]; then
6060+ for ((i = 0; i < ${#words[@]}; i++)); do
6161+ if [[ "${words[i]}" == "--" ]]; then
6262 _comp_command_offset $((i+1))
6363 return
6464 fi