completion/git: expand search range
- Remove limitation on OS. - Add search for Mac OS X developer tools locations by using `xcrun` instead of trying to guess paths. - Add search for locations based on path of `$GIT_EXE` (set by `lib/theme`).pull/1965/head
parent
d6c4c0cc88
commit
e22aac855e
|
|
@ -1,28 +1,31 @@
|
||||||
#!/usr/bin/env bash
|
# shellcheck shell=bash
|
||||||
|
#
|
||||||
# Only operate on MacOS since there are no linux paths
|
# Locate and load completions for `git`.
|
||||||
if [[ "$OSTYPE" != 'darwin'* ]] ; then
|
|
||||||
_log_warning "unsupported operating system - only 'Darwin' is supported"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Make sure git is installed
|
# Make sure git is installed
|
||||||
_command_exists git || return 0
|
_command_exists git || return
|
||||||
|
|
||||||
# Don't handle completion if it's already managed
|
# Don't handle completion if it's already managed
|
||||||
if complete -p git &>/dev/null ; then
|
if complete -p git &>/dev/null; then
|
||||||
_log_warning "completion already loaded - this usually means it is safe to stop using this completion"
|
_log_warning "completion already loaded - this usually means it is safe to stop using this completion"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
_git_bash_completion_found=false
|
_git_bash_completion_xcrun_git=
|
||||||
|
if _command_exists xcrun; then
|
||||||
|
_git_bash_completion_xcrun_git="$(xcrun --find git)"
|
||||||
|
fi
|
||||||
_git_bash_completion_paths=(
|
_git_bash_completion_paths=(
|
||||||
|
# Standard locations
|
||||||
|
"${GIT_EXE%/*}/../share/git-core/git-completion.bash"
|
||||||
|
"${GIT_EXE%/*}/../share/git-core/contrib/completion/git-completion.bash"
|
||||||
|
"${GIT_EXE%/*}/../etc/bash_completion.d/git-completion.bash"
|
||||||
# MacOS non-system locations
|
# MacOS non-system locations
|
||||||
'/Library/Developer/CommandLineTools/usr/share/git-core/git-completion.bash'
|
"${_git_bash_completion_xcrun_git%/bin/git}/share/git-core/git-completion.bash"
|
||||||
'/Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-completion.bash'
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Load the first completion file found
|
# Load the first completion file found
|
||||||
|
_git_bash_completion_found=false
|
||||||
for _comp_path in "${_git_bash_completion_paths[@]}" ; do
|
for _comp_path in "${_git_bash_completion_paths[@]}" ; do
|
||||||
if [[ -r "$_comp_path" ]] ; then
|
if [[ -r "$_comp_path" ]] ; then
|
||||||
_git_bash_completion_found=true
|
_git_bash_completion_found=true
|
||||||
|
|
@ -35,5 +38,4 @@ done
|
||||||
if [[ "${_git_bash_completion_found}" == false ]]; then
|
if [[ "${_git_bash_completion_found}" == false ]]; then
|
||||||
_log_warning "no completion files found - please try enabling the 'system' completion instead."
|
_log_warning "no completion files found - please try enabling the 'system' completion instead."
|
||||||
fi
|
fi
|
||||||
unset _git_bash_completion_paths
|
unset "${!_git_bash_completion@}"
|
||||||
unset _git_bash_completion_found
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue