Skip to content

Commit d71a5f7

Browse files
committed
fix(zsh): Repair broken completion of --git-opt
The brace expansion for iterating over the `--git-opt` values from the command line (i.e. `{2..2..$(($#git_opts - 2))}`) was broken in a couple ways. First, in `{n1..n2..n3}`, n2 is the end number and n3 is the step value, but these were transposed. Second, in order to avoid backwards sequences, we need to ensure that the end number is greater than the start number. A condition is added to test that.
1 parent 1a46d8a commit d71a5f7

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

completion/stgit.zsh

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,21 +1226,25 @@ __stg_complete_git_opts() {
12261226
# The option values are at the even indexes in the git_opts array.
12271227
# The last option is skipped because it is the partially specified one being
12281228
# completed.
1229-
for i in {2..2..$(($#git_opts - 2))}; do
1230-
# Need to strip any leading '=' because zparseopts will parse, for example,
1231-
# `--diff-opt=foo` as ('--diff-opt' '=foo').
1232-
words+=(${git_opts[i]#=})
1233-
done
1229+
if (( $#git_opts > 2 )); then
1230+
for i in {1..$(($#git_opts - 2))..2}; do
1231+
# Need to strip any leading '=' because zparseopts will parse, for example,
1232+
# `--diff-opt=foo` as ('--diff-opt' '=foo').
1233+
words+=(${git_opts[i+1]#=})
1234+
done
1235+
fi
12341236

12351237
# If the user has not started typing the value, prime it with '-' to force
12361238
# completing only the options (and not arguments) to the git command.
12371239
: ${SUFFIX:-${PREFIX:=-}}
12381240
words+=("$PREFIX$SUFFIX")
12391241
(( CURRENT = $#words ))
12401242

1241-
for i in {2..2..$#git_opts_after}; do
1242-
words+=(${git_opts_after[i]#=})
1243-
done
1243+
if (( $#git_opts_after > 2 )); then
1244+
for i in {1..$(($#git_opts_after - 2))..2}; do
1245+
words+=(${git_opts_after[i+1]#=})
1246+
done
1247+
fi
12441248

12451249
_message -e "git-$git_cmd-option" "git $git_cmd" &&
12461250
_dispatch git git $commands[git]

0 commit comments

Comments
 (0)