Skip to content

Commit ebb9d19

Browse files
committed
Merge branch 'bc/completion-for-bash-3.0' into maint
Some people still use rather old versions of bash, which cannot grok some constructs like 'printf -v varname' the prompt and completion code started to use recently. * bc/completion-for-bash-3.0: contrib/git-prompt.sh: handle missing 'printf -v' more gracefully t9902-completion.sh: old Bash still does not support array+=('') notation git-completion.bash: use correct Bash/Zsh array length syntax
2 parents b25b9d5 + a44aa69 commit ebb9d19

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

contrib/completion/git-completion.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2580,7 +2580,7 @@ if [[ -n ${ZSH_VERSION-} ]]; then
25802580
--*=*|*.) ;;
25812581
*) c="$c " ;;
25822582
esac
2583-
array[$#array+1]="$c"
2583+
array[${#array[@]}+1]="$c"
25842584
done
25852585
compset -P '*[=:]'
25862586
compadd -Q -S '' -p "${2-}" -a -- array && _ret=0

contrib/completion/git-prompt.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@
8484
# the colored output of "git status -sb" and are available only when
8585
# using __git_ps1 for PROMPT_COMMAND or precmd.
8686

87+
# check whether printf supports -v
88+
__git_printf_supports_v=
89+
printf -v __git_printf_supports_v -- '%s' yes >/dev/null 2>&1
90+
8791
# stores the divergence from upstream in $p
8892
# used by GIT_PS1_SHOWUPSTREAM
8993
__git_ps1_show_upstream ()
@@ -433,7 +437,7 @@ __git_ps1 ()
433437
local gitstring="$c${b##refs/heads/}${f:+$z$f}$r$p"
434438

435439
if [ $pcmode = yes ]; then
436-
if [[ -n ${ZSH_VERSION-} ]]; then
440+
if [ "${__git_printf_supports_v-}" != yes ]; then
437441
gitstring=$(printf -- "$printf_format" "$gitstring")
438442
else
439443
printf -v gitstring -- "$printf_format" "$gitstring"

t/t9902-completion.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ run_completion ()
6969
local -a COMPREPLY _words
7070
local _cword
7171
_words=( $1 )
72-
test "${1: -1}" = ' ' && _words+=('')
72+
test "${1: -1}" = ' ' && _words[${#_words[@]}+1]=''
7373
(( _cword = ${#_words[@]} - 1 ))
7474
__git_wrap__git_main && print_comp
7575
}

0 commit comments

Comments
 (0)