From ae5131aee23a892b0e8708efc6b58cb0aeb46160 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 9 Oct 2021 11:48:55 -0700 Subject: [PATCH] completion/subversion: load system completion Load the completion script from the subversion package installed on the system, instead of bundling a copy. This addresses Bash-it/bash-it#1818. NOTE: If `completions/system` is enabled, then it will load this same file anyway automatically. --- .../available/subversion.completion.bash | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 completion/available/subversion.completion.bash diff --git a/completion/available/subversion.completion.bash b/completion/available/subversion.completion.bash new file mode 100644 index 00000000..2f0a23fe --- /dev/null +++ b/completion/available/subversion.completion.bash @@ -0,0 +1,40 @@ +# shellcheck shell=bash +# +# Locate and load completions for `svn`. + +# Make sure svn is installed +_command_exists svn || return + +# Don't handle completion if it's already managed +if _completion_exists svn; then + _log_warning "completion already loaded - this usually means it is safe to stop using this completion" + return 0 +fi + +_svn_bash_completion_xcrun_svn= +if _command_exists xcrun; then + _svn_bash_completion_xcrun_svn="$(xcrun --find svn)" +fi +_svn_bash_completion_paths=( + # Standard locations + "${SVN_EXE%/*}/../etc/bash_completion.d/subversion" + # MacOS non-system locations + "${_svn_bash_completion_xcrun_svn%/bin/svn}/etc/bash_completion.d/subversion" +) + +# Load the first completion file found +_svn_bash_completion_found=false +for _comp_path in "${_svn_bash_completion_paths[@]}"; do + if [[ -r "$_comp_path" ]]; then + _svn_bash_completion_found=true + # shellcheck disable=SC1090 # don't follow + source "$_comp_path" + break + fi +done + +# Cleanup +if [[ "${_svn_bash_completion_found}" == false ]]; then + _log_warning "no completion files found - please try enabling the 'system' completion instead." +fi +unset "${!_svn_bash_completion@}"