Merge pull request #1965 from gaelicWizard/completion-git

completion/git: improvements and linting
pull/1971/head
Noah Gorny 2021-10-07 00:10:47 +03:00 committed by GitHub
commit cf08fcaff2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 24 deletions

View File

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

View File

@ -1,13 +1,9 @@
#!/usr/bin/env bash
# Only operate on MacOS since there are no linux paths
if [[ "$OSTYPE" != 'darwin'* ]] ; then
_log_warning "unsupported operating system - only 'Darwin' is supported"
return 0
fi
# shellcheck shell=bash
#
# Locate and load completions for `git`.
# Make sure git is installed
_command_exists git || return 0
_command_exists git || return
# Don't handle completion if it's already managed
if complete -p git &> /dev/null; then
@ -15,17 +11,25 @@ if complete -p git &>/dev/null ; then
return 0
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=(
# 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
'/Library/Developer/CommandLineTools/usr/share/git-core/git-completion.bash'
'/Applications/Xcode.app/Contents/Developer/usr/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
_git_bash_completion_found=false
for _comp_path in "${_git_bash_completion_paths[@]}"; do
if [[ -r "$_comp_path" ]]; then
_git_bash_completion_found=true
# shellcheck disable=SC1090 # don't follow
source "$_comp_path"
break
fi
@ -35,5 +39,4 @@ done
if [[ "${_git_bash_completion_found}" == false ]]; then
_log_warning "no completion files found - please try enabling the 'system' completion instead."
fi
unset _git_bash_completion_paths
unset _git_bash_completion_found
unset "${!_git_bash_completion@}"