Skip to content
Myr

Add flaghash to bash_completion to keep flag value

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Kenjiro Nakayama · committed by Steve Francia · parent 2bd8a73 · Browse files · 1 file+12 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+12 added−1 removed

  • other:+12 added−1 removed

1 file+12 added−1 removed

modified:bash_completions.go+12 added-1 removed
124 unmodified lines
125 __debug "${FUNCNAME}: c is $c words[c] is ${words[c]}"126127 # if a command required a flag, and we found it, unset must_have_one_flag()128 local flagname=${words[c]}129 local flagvalue130 # if the word contained an =131 if [[ ${words[c]} == *"="* ]]; then132 flagvalue=${flagname#*=} # take in as flagvalue after the =133 flagname=${flagname%%=*} # strip everything after the =134 flagname="${flagname}=" # but put the = back135 fi136 __debug "${FUNCNAME}: looking for ${flagname}"137 if __contains_word "${flagname}" "${must_have_one_flag[@]}"; then138 must_have_one_flag=()139 fi140141 # keep flag value with flagname as flaghash142 if [ ${flagvalue} ] ; then143 flaghash[${flagname}]=${flagvalue}144 elif [ ${words[ $((c+1)) ]} ] ; then145 flaghash[${flagname}]=${words[ $((c+1)) ]}146 else147 flaghash[${flagname}]="true" # pad "true" for bool flag148 fi149150 # skip the argument to a two word flag151 if __contains_word "${words[c]}" "${two_word_flags[@]}"; then152 c=$((c+1))153 # if we are looking for a flags value, don't show commands
1 unmodified line
155 commands=()156 fi157 fi158148 # skip the flag itself159 c=$((c+1))160161}162
48 unmodified lines
211 name = strings.Replace(name, ":", "__", -1)212 fmt.Fprintf(out, "__start_%s()\n", name)213 fmt.Fprintf(out, `{214 local cur prev words cword215 declare -A flaghash216 if declare -F _init_completion >/dev/null 2>&1; then217 _init_completion -s || return218 else219 __my_init_completion || return
221 unmodified lines