Skip to content

Commit cf08fca

Browse files
authoredOct 6, 2021
Merge pull request Bash-it#1965 from gaelicWizard/completion-git
completion/git: improvements and linting
2 parents c3382c7 + b0750fa commit cf08fca

File tree

2 files changed

+28
-24
lines changed

2 files changed

+28
-24
lines changed
 

‎clean_files.txt

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ completion/available/docker-machine.completion.bash
4949
completion/available/docker.completion.bash
5050
completion/available/gcloud.completion.bash
5151
completion/available/gem.completion.bash
52+
completion/available/git.completion.bash
5253
completion/available/github-cli.completion.bash
5354
completion/available/go.completion.bash
5455
completion/available/helm.completion.bash
+27-24
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,42 @@
1-
#!/usr/bin/env bash
2-
3-
# Only operate on MacOS since there are no linux paths
4-
if [[ "$OSTYPE" != 'darwin'* ]] ; then
5-
_log_warning "unsupported operating system - only 'Darwin' is supported"
6-
return 0
7-
fi
1+
# shellcheck shell=bash
2+
#
3+
# Locate and load completions for `git`.
84

95
# Make sure git is installed
10-
_command_exists git || return 0
6+
_command_exists git || return
117

128
# Don't handle completion if it's already managed
13-
if complete -p git &>/dev/null ; then
14-
_log_warning "completion already loaded - this usually means it is safe to stop using this completion"
15-
return 0
9+
if complete -p git &> /dev/null; then
10+
_log_warning "completion already loaded - this usually means it is safe to stop using this completion"
11+
return 0
1612
fi
1713

18-
_git_bash_completion_found=false
14+
_git_bash_completion_xcrun_git=
15+
if _command_exists xcrun; then
16+
_git_bash_completion_xcrun_git="$(xcrun --find git)"
17+
fi
1918
_git_bash_completion_paths=(
20-
# MacOS non-system locations
21-
'/Library/Developer/CommandLineTools/usr/share/git-core/git-completion.bash'
22-
'/Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-completion.bash'
19+
# Standard locations
20+
"${GIT_EXE%/*}/../share/git-core/git-completion.bash"
21+
"${GIT_EXE%/*}/../share/git-core/contrib/completion/git-completion.bash"
22+
"${GIT_EXE%/*}/../etc/bash_completion.d/git-completion.bash"
23+
# MacOS non-system locations
24+
"${_git_bash_completion_xcrun_git%/bin/git}/share/git-core/git-completion.bash"
2325
)
2426

2527
# Load the first completion file found
26-
for _comp_path in "${_git_bash_completion_paths[@]}" ; do
27-
if [[ -r "$_comp_path" ]] ; then
28-
_git_bash_completion_found=true
29-
source "$_comp_path"
30-
break
31-
fi
28+
_git_bash_completion_found=false
29+
for _comp_path in "${_git_bash_completion_paths[@]}"; do
30+
if [[ -r "$_comp_path" ]]; then
31+
_git_bash_completion_found=true
32+
# shellcheck disable=SC1090 # don't follow
33+
source "$_comp_path"
34+
break
35+
fi
3236
done
3337

3438
# Cleanup
3539
if [[ "${_git_bash_completion_found}" == false ]]; then
36-
_log_warning "no completion files found - please try enabling the 'system' completion instead."
40+
_log_warning "no completion files found - please try enabling the 'system' completion instead."
3741
fi
38-
unset _git_bash_completion_paths
39-
unset _git_bash_completion_found
42+
unset "${!_git_bash_completion@}"

0 commit comments

Comments
 (0)
Please sign in to comment.