completion/git: `shfmt` && `shellcheck`

pull/1965/head
John D Pell 2021-09-24 21:10:32 -07:00
parent e22aac855e
commit b0750fa49f
2 changed files with 18 additions and 16 deletions

View File

@ -49,6 +49,7 @@ completion/available/docker-machine.completion.bash
completion/available/docker.completion.bash completion/available/docker.completion.bash
completion/available/gcloud.completion.bash completion/available/gcloud.completion.bash
completion/available/gem.completion.bash completion/available/gem.completion.bash
completion/available/git.completion.bash
completion/available/github-cli.completion.bash completion/available/github-cli.completion.bash
completion/available/go.completion.bash completion/available/go.completion.bash
completion/available/helm.completion.bash completion/available/helm.completion.bash

View File

@ -6,9 +6,9 @@
_command_exists git || return _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_xcrun_git= _git_bash_completion_xcrun_git=
@ -16,26 +16,27 @@ if _command_exists xcrun; then
_git_bash_completion_xcrun_git="$(xcrun --find git)" _git_bash_completion_xcrun_git="$(xcrun --find git)"
fi fi
_git_bash_completion_paths=( _git_bash_completion_paths=(
# Standard locations # Standard locations
"${GIT_EXE%/*}/../share/git-core/git-completion.bash" "${GIT_EXE%/*}/../share/git-core/git-completion.bash"
"${GIT_EXE%/*}/../share/git-core/contrib/completion/git-completion.bash" "${GIT_EXE%/*}/../share/git-core/contrib/completion/git-completion.bash"
"${GIT_EXE%/*}/../etc/bash_completion.d/git-completion.bash" "${GIT_EXE%/*}/../etc/bash_completion.d/git-completion.bash"
# MacOS non-system locations # MacOS non-system locations
"${_git_bash_completion_xcrun_git%/bin/git}/share/git-core/git-completion.bash" "${_git_bash_completion_xcrun_git%/bin/git}/share/git-core/git-completion.bash"
) )
# Load the first completion file found # Load the first completion file found
_git_bash_completion_found=false _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
source "$_comp_path" # shellcheck disable=SC1090 # don't follow
break source "$_comp_path"
fi break
fi
done done
# Cleanup # Cleanup
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@}" unset "${!_git_bash_completion@}"