diff --git a/contrib/tig-completion.bash b/contrib/tig-completion.bash index 4a9deb05d..6aaa9b37c 100755 --- a/contrib/tig-completion.bash +++ b/contrib/tig-completion.bash @@ -1,5 +1,5 @@ # bash/zsh completion for tig -# +# # Copyright (C) 2019 Roland Hieber, Pengutronix # Copyright (C) 2007-2010 Jonas fonseca # @@ -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