The unpac monorepo manager self-hosting as a monorepo using unpac

bash completion: include = as part of completion token

Fix #231 point 1. Close #242

authored by

Brian Ward and committed by
Daniel Bünzli
c22bce1b 2bd898f4

+26 -25
+2 -1
CHANGES.md
··· 1 1 2 - 2 + - Improve bash completion of long options with `=` (#231). 3 + Thanks to Brian Ward for the patch. 3 4 - Improve bash completion on files and directories (#238). 4 5 Thanks to Brian Ward for the report and fix. 5 6
+12 -12
src/tool/bash-completion.sh
··· 1 1 _cmdliner_generic() { 2 - local prefix="${COMP_WORDS[COMP_CWORD]}" 3 - local w=("${COMP_WORDS[@]}") # Keep COMP_WORDS intact for restart completion 4 - w[COMP_CWORD]="--__complete=${COMP_WORDS[COMP_CWORD]}" 2 + local words cword 3 + # Equivalent of COMP_WORDS, COMP_CWORD but allow us to exclude '=' as a word separator 4 + _get_comp_words_by_ref -n = words cword 5 + 6 + local prefix="${words[cword]}" 7 + local w=("${words[@]}") # Keep words intact for restart completion 8 + w[cword]="--__complete=${words[cword]}" 5 9 local line="${w[@]:0:1} --__complete ${w[@]:1}" 6 10 local version type group item text_line item_doc msg 7 11 { ··· 45 49 done 46 50 # Sadly it seems bash does not support doc strings, so we only 47 51 # add item to to the reply. If you know any better get in touch. 48 - # Handle glued forms, the completion item is the full option 49 - if [[ $group == "Values" ]]; then 50 - if [[ $prefix == --* ]]; then 51 - item="${prefix%%=*}=$item" 52 - elif [[ $prefix == -* ]]; then 53 - item="${prefix:0:2}$item" 54 - fi 52 + if [[ $group == "Values" ]] && [[ $prefix == -* ]] && [[ $prefix != --* ]]; then 53 + # properly complete short options 54 + item="${prefix:0:2}$item" 55 55 fi 56 56 COMPREPLY+=($item) 57 57 elif [[ $type == "restart" ]]; then 58 58 # N.B. only emitted if there is a -- token 59 - for ((i = 0; i < ${#COMP_WORDS[@]}; i++)); do 60 - if [[ "${COMP_WORDS[i]}" == "--" ]]; then 59 + for ((i = 0; i < ${#words[@]}; i++)); do 60 + if [[ "${words[i]}" == "--" ]]; then 61 61 _comp_command_offset $((i+1)) 62 62 return 63 63 fi
+12 -12
src/tool/cmdliner_data.ml
··· 1 1 let bash_generic_completion = 2 2 {|_cmdliner_generic() { 3 - local prefix="${COMP_WORDS[COMP_CWORD]}" 4 - local w=("${COMP_WORDS[@]}") # Keep COMP_WORDS intact for restart completion 5 - w[COMP_CWORD]="--__complete=${COMP_WORDS[COMP_CWORD]}" 3 + local words cword 4 + # Equivalent of COMP_WORDS, COMP_CWORD but allow us to exclude '=' as a word separator 5 + _get_comp_words_by_ref -n = words cword 6 + 7 + local prefix="${words[cword]}" 8 + local w=("${words[@]}") # Keep words intact for restart completion 9 + w[cword]="--__complete=${words[cword]}" 6 10 local line="${w[@]:0:1} --__complete ${w[@]:1}" 7 11 local version type group item text_line item_doc msg 8 12 { ··· 46 50 done 47 51 # Sadly it seems bash does not support doc strings, so we only 48 52 # add item to to the reply. If you know any better get in touch. 49 - # Handle glued forms, the completion item is the full option 50 - if [[ $group == "Values" ]]; then 51 - if [[ $prefix == --* ]]; then 52 - item="${prefix%%=*}=$item" 53 - elif [[ $prefix == -* ]]; then 54 - item="${prefix:0:2}$item" 55 - fi 53 + if [[ $group == "Values" ]] && [[ $prefix == -* ]] && [[ $prefix != --* ]]; then 54 + # properly complete short options 55 + item="${prefix:0:2}$item" 56 56 fi 57 57 COMPREPLY+=($item) 58 58 elif [[ $type == "restart" ]]; then 59 59 # N.B. only emitted if there is a -- token 60 - for ((i = 0; i < ${#COMP_WORDS[@]}; i++)); do 61 - if [[ "${COMP_WORDS[i]}" == "--" ]]; then 60 + for ((i = 0; i < ${#words[@]}; i++)); do 61 + if [[ "${words[i]}" == "--" ]]; then 62 62 _comp_command_offset $((i+1)) 63 63 return 64 64 fi