@@ -1207,38 +1207,42 @@ __stg_add_args_trailers() {
1207
1207
}
1208
1208
1209
1209
__stg_complete_git_opts () {
1210
- local gitcmd short long
1211
- gitcmd =$1
1210
+ local git_cmd short long i
1211
+ git_cmd =$1
1212
1212
short=$2
1213
1213
long=$3
1214
1214
1215
1215
# Parse short and long options (e.g. -O and --diff-opt) from $words.
1216
- declare -a gitopts
1217
- function {
1218
- zparseopts -E -D ${short} +:=gitopts -${long} +:=gitopts 2> /dev/null
1219
- } $words
1216
+ declare -a git_opts git_opts_after
1217
+ zmodload -F ' zsh/zutil' ' b:zparseopts'
1218
+ () { zparseopts -E -D -a git_opts ${short} +: -${long} +: 2> /dev/null; } \
1219
+ ${(@ )words[1,CURRENT]}
1220
+ () { zparseopts -E -D -a git_opts_after ${short} +: -${long} +: 2> /dev/null; } \
1221
+ ${(@ )words[CURRENT+1,-1]}
1220
1222
1221
1223
# Compose git command line
1222
- words=(' git' ${(@ )__stg_C_args} ${gitcmd } )
1224
+ words=(' git' ${(@ )__stg_C_args} ${git_cmd } )
1223
1225
1224
- # The option values are at the even indexes in the gitopts array.
1226
+ # The option values are at the even indexes in the git_opts array.
1225
1227
# The last option is skipped because it is the partially specified one being
1226
1228
# completed.
1227
- for i in $( seq 2 2 $(( $# gitopts - 2 )) ) ; do
1229
+ for i in {2..2.. $(( $# git_opts - 2 )) } ; do
1228
1230
# Need to strip any leading '=' because zparseopts will parse, for example,
1229
1231
# `--diff-opt=foo` as ('--diff-opt' '=foo').
1230
- words+=${gitopts [i]# =}
1232
+ words+=( ${git_opts [i]# =})
1231
1233
done
1232
1234
1233
1235
# If the user has not started typing the value, prime it with '-' to force
1234
1236
# completing only the options (and not arguments) to the git command.
1235
- if [ -z " $PREFIX " -a -z " $SUFFIX " ]; then
1236
- PREFIX=' -'
1237
- fi
1238
- words+=" $PREFIX$SUFFIX "
1237
+ : ${SUFFIX:- ${PREFIX:= -} }
1238
+ words+=(" $PREFIX$SUFFIX " )
1239
1239
(( CURRENT = $# words ))
1240
1240
1241
- _message -e " git-$gitcmd -option" " git $gitcmd " &&
1241
+ for i in {2..2..$# git_opts_after}; do
1242
+ words+=(${git_opts_after[i]# =} )
1243
+ done
1244
+
1245
+ _message -e " git-$git_cmd -option" " git $git_cmd " &&
1242
1246
_dispatch git git $commands [git]
1243
1247
}
1244
1248
0 commit comments