Skip to content

Commit

Permalink
Upgrade to only support v2 bash_completion.
Browse files Browse the repository at this point in the history
This eliminates some cruft for supporting bash_completion v1, which is
really unnecessary at this point. Even servers used within all
infrastructure I manage are modern and support v2, like CentOS 7.

Note that this work was done in response to debugging why git
completions were not working. In the end, it had to do with the
installation of GitHub's hub utility: mislav/hub#2684. Ultimatelty,
hub was removed until that is fixed.
  • Loading branch information
danemacmillan committed Feb 9, 2021
1 parent 433dcbe commit 4b29e77
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 41 deletions.
42 changes: 13 additions & 29 deletions home/.bashrc
Original file line number Diff line number Diff line change
Expand Up @@ -234,45 +234,29 @@ fi
# faster than original `bash-completion` package.
# Read: https://superuser.com/a/1393343/496301
#
# Note that brew recommends sourcing /usr/local/etc/profile.d/bash_completion.sh
# for either version of bash-completion. These dotfiles have chosen to
# explicitly look for version 2, and if found, assign a backwards-compatible
# directory to look for old-style, eagerly-loaded bash completion files, then
# source the new, faster ones that are non-eager. Doing so allows the old
# bash-completion files to be picked up, of which there are several, including
# those for git completion and vagrant completion. This works because
# version 2 of bash completion checks for a `$BASH_COMPLETION_COMPAT_DIR`
# variable, and if found, will immediately source all the files found under it.
# It exclusively support version 2, and provide fallback support for any
# utilities that have not updated, using the `$BASH_COMPLETION_COMPAT_DIR`
# path. Multiple locations are searched: the usual MacOS path is first checked,
# then a common path on Linux systems, like CentOS.
#
# Additionally, the $BASH_COMPLETION_USER_FILE environment variable is set,
# which by default points to `~/.bash_completion`, but instead has been moved to
# an XDG directory. Note that this user file is sourced eagerly as well, so
# should not be used, except in cases where a popular tool does not offer a
# better alternative. For the purpose of distinguishing old-style eager
# completions from modern non-eager completions, this user completion file
# has been added to a path under $XDG_CONFIG_HOME. Non-eager user completions
# are available under the new path, under $XDG_DATA_HOME.
# has been added to a path under $XDG_CONFIG_HOME.
#
# Non-eager user completions are available under the new path, under
# $XDG_DATA_HOME. This is where all new completions should be added.
export BASH_COMPLETION_USER_DIR="${XDG_DATA_HOME}/bash-completion/completions"
export BASH_COMPLETION_USER_FILE="${XDG_CONFIG_HOME}/bash-completion/bash_completion"
if [[ -e "/usr/local/share/bash-completion/bash_completion" ]]; then
if [[ -e "/usr/local/etc/profile.d/bash_completion.sh" ]]; then
export BASH_COMPLETION_COMPAT_DIR="/usr/local/etc/bash_completion.d"
source "/usr/local/share/bash-completion/bash_completion"
elif [[ -e "/usr/local/etc/profile.d/bash_completion.sh" ]]; then
source "/usr/local/etc/profile.d/bash_completion.sh"
elif [[ -e "/etc/bash_completion" ]]; then
# This is in all certainty NOT version 2 bash completion, so pull them in
# eagerly. Note that this requires sudo privileges to add a user's completion
# file to /etc/bash_completion. This is really a last-ditch effort to get
# v1 completion compatibility on old systems. A simple
# ${HOME}/.bash_completion can also just be created, but the goal of thee
# dotfiles is to follow the XDG spec as closely as possible, in an effort to
# clean up the home directory.
#if [[ "${BASH_COMPLETION_VERSINFO}" != "2" ]] \
# && [[ ! -e "/etc/bash_completion.d/bash_completion.${USER}" ]] \
#; then
# sudo ln -s "${BASH_COMPLETION_USER_FILE}" "/etc/bash_completion.d/bash_completion.${USER}"
#fi

source "/etc/bash_completion"
elif [[ -e "/etc/profile.d/bash_completion.sh" ]]; then
export BASH_COMPLETION_COMPAT_DIR="/etc/bash_completion.d"
source "/etc/profile.d/bash_completion.sh"
fi

##
Expand Down
12 changes: 0 additions & 12 deletions home/.config/bash-completion/bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,6 @@
# @link https://github.com/danemacmillan/dotfiles
# @license MIT

# Pull in bash completion from version 2 location, and have these loaded
# eagerly. Note that this particular file also needs to be either symlinked
# into the v1 path at /etc/bash_completion.d, or a ~/.bash_completion file
# should source this one.
if [[ "${BASH_COMPLETION_VERSINFO}" != "2" ]]; then
if [[ -e "${XDG_DATA_HOME}/bash-completion/completions" ]]; then
for completion_file in "${XDG_DATA_HOME}/bash-completion/completions/"*; do
source "${completion_file}"
done
fi
fi

# Source google-cloud-sdk gcloud utilities
# https://cloud.google.com/sdk/docs/quickstarts
if [[ -f "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/completion.bash.inc" ]]; then
Expand Down
3 changes: 3 additions & 0 deletions home/.config/bash_completion
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# See https://github.com/scop/bash-completion/blob/master/doc/bash_completion.txt


0 comments on commit 4b29e77

Please sign in to comment.