Skip to content

Commit

Permalink
Handle undefined __git_complete (#1055)
Browse files Browse the repository at this point in the history
As identified in #1011 (comment), there are cases where `__git_complete` is undefined because it is loaded dynamically by bash_completions.

As suggested in #1011 (comment), using `pkg-config` to find `git-completion` script, which defines `__git_complete`.  And using approach similar to https://github.com/felipec/git-completion/blob/master/git-completion.zsh#L28-L49.

Fixes #1011
  • Loading branch information
darcyparker authored Dec 13, 2020
1 parent 04cc156 commit 9d7b5cd
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion contrib/tig-completion.bash
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# bash/zsh completion for tig
#
#
# Copyright (C) 2019 Roland Hieber, Pengutronix
# Copyright (C) 2007-2010 Jonas fonseca
#
Expand Down Expand Up @@ -29,6 +29,27 @@
# at source time then all lookups will be done on demand,
# which may be slightly slower.

#tig-completion requires __git_complete
#* If not defined, source git completions script so __git_complete is available
if ! declare -f __git_complete &>/dev/null; then
_bash_completion=$(pkg-config --variable=completionsdir bash-completion 2>/dev/null) ||
_bash_completion='/usr/share/bash-completion/completions/'
_locations=(
"$(dirname "${BASH_SOURCE[0]%:*}")"/git-completion.bash #in same dir as this
"$HOME/.local/share/bash-completion/completions/git"
"$_bash_completion/git"
'/etc/bash_completion.d/git' # old debian
)
for _e in "${_locations[@]}"; do
# shellcheck disable=1090
test -f "$_e" && . "$_e" && break
done
unset _bash_completion _locations _e
if ! declare -f __git_complete &>/dev/null; then
return #silently return without completions
fi
fi

__tig_options="
-v --version
-h --help
Expand Down

0 comments on commit 9d7b5cd

Please sign in to comment.