From e22aac855ef7bf2b9d09f086d64df272bdd23d1b Mon Sep 17 00:00:00 2001
From: John D Pell <John+git@gaelicWizard.net>
Date: Fri, 24 Sep 2021 21:10:01 -0700
Subject: [PATCH 1/2] 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`).
---
 completion/available/git.completion.bash | 30 +++++++++++++-----------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/completion/available/git.completion.bash b/completion/available/git.completion.bash
index b9bb1bb6..16b21f2c 100644
--- a/completion/available/git.completion.bash
+++ b/completion/available/git.completion.bash
@@ -1,28 +1,31 @@
-#!/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
+if complete -p git &>/dev/null; then
   _log_warning "completion already loaded - this usually means it is safe to stop using this completion"
   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
@@ -35,5 +38,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@}"

From b0750fa49fcdc4fe102ea6b907c3a7b9ac0518a3 Mon Sep 17 00:00:00 2001
From: John D Pell <John+git@gaelicWizard.net>
Date: Fri, 24 Sep 2021 21:10:32 -0700
Subject: [PATCH 2/2] completion/git: `shfmt` && `shellcheck`

---
 clean_files.txt                          |  1 +
 completion/available/git.completion.bash | 33 ++++++++++++------------
 2 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/clean_files.txt b/clean_files.txt
index 2242ef5e..cff2c60b 100644
--- a/clean_files.txt
+++ b/clean_files.txt
@@ -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
diff --git a/completion/available/git.completion.bash b/completion/available/git.completion.bash
index 16b21f2c..31b77fa3 100644
--- a/completion/available/git.completion.bash
+++ b/completion/available/git.completion.bash
@@ -6,9 +6,9 @@
 _command_exists git || return
 
 # Don't handle completion if it's already managed
-if complete -p git &>/dev/null; then
-  _log_warning "completion already loaded - this usually means it is safe to stop using this completion"
-  return 0
+if complete -p git &> /dev/null; then
+	_log_warning "completion already loaded - this usually means it is safe to stop using this completion"
+	return 0
 fi
 
 _git_bash_completion_xcrun_git=
@@ -16,26 +16,27 @@ 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
-  "${_git_bash_completion_xcrun_git%/bin/git}/share/git-core/git-completion.bash"
+	# 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
+	"${_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
-    source "$_comp_path"
-    break
-  fi
+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
 done
 
 # Cleanup
 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
 unset "${!_git_bash_completion@}"
