Skip to content

Commit 4b29e77

Browse files
committed
Upgrade to only support v2 bash_completion.
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.
1 parent 433dcbe commit 4b29e77

File tree

3 files changed

+16
-41
lines changed

3 files changed

+16
-41
lines changed

home/.bashrc

+13-29
Original file line numberDiff line numberDiff line change
@@ -234,45 +234,29 @@ fi
234234
# faster than original `bash-completion` package.
235235
# Read: https://superuser.com/a/1393343/496301
236236
#
237-
# Note that brew recommends sourcing /usr/local/etc/profile.d/bash_completion.sh
238-
# for either version of bash-completion. These dotfiles have chosen to
239-
# explicitly look for version 2, and if found, assign a backwards-compatible
240-
# directory to look for old-style, eagerly-loaded bash completion files, then
241-
# source the new, faster ones that are non-eager. Doing so allows the old
242-
# bash-completion files to be picked up, of which there are several, including
243-
# those for git completion and vagrant completion. This works because
244-
# version 2 of bash completion checks for a `$BASH_COMPLETION_COMPAT_DIR`
245-
# variable, and if found, will immediately source all the files found under it.
237+
# It exclusively support version 2, and provide fallback support for any
238+
# utilities that have not updated, using the `$BASH_COMPLETION_COMPAT_DIR`
239+
# path. Multiple locations are searched: the usual MacOS path is first checked,
240+
# then a common path on Linux systems, like CentOS.
246241
#
247242
# Additionally, the $BASH_COMPLETION_USER_FILE environment variable is set,
248243
# which by default points to `~/.bash_completion`, but instead has been moved to
249244
# an XDG directory. Note that this user file is sourced eagerly as well, so
250245
# should not be used, except in cases where a popular tool does not offer a
251246
# better alternative. For the purpose of distinguishing old-style eager
252247
# completions from modern non-eager completions, this user completion file
253-
# has been added to a path under $XDG_CONFIG_HOME. Non-eager user completions
254-
# are available under the new path, under $XDG_DATA_HOME.
248+
# has been added to a path under $XDG_CONFIG_HOME.
249+
#
250+
# Non-eager user completions are available under the new path, under
251+
# $XDG_DATA_HOME. This is where all new completions should be added.
252+
export BASH_COMPLETION_USER_DIR="${XDG_DATA_HOME}/bash-completion/completions"
255253
export BASH_COMPLETION_USER_FILE="${XDG_CONFIG_HOME}/bash-completion/bash_completion"
256-
if [[ -e "/usr/local/share/bash-completion/bash_completion" ]]; then
254+
if [[ -e "/usr/local/etc/profile.d/bash_completion.sh" ]]; then
257255
export BASH_COMPLETION_COMPAT_DIR="/usr/local/etc/bash_completion.d"
258-
source "/usr/local/share/bash-completion/bash_completion"
259-
elif [[ -e "/usr/local/etc/profile.d/bash_completion.sh" ]]; then
260256
source "/usr/local/etc/profile.d/bash_completion.sh"
261-
elif [[ -e "/etc/bash_completion" ]]; then
262-
# This is in all certainty NOT version 2 bash completion, so pull them in
263-
# eagerly. Note that this requires sudo privileges to add a user's completion
264-
# file to /etc/bash_completion. This is really a last-ditch effort to get
265-
# v1 completion compatibility on old systems. A simple
266-
# ${HOME}/.bash_completion can also just be created, but the goal of thee
267-
# dotfiles is to follow the XDG spec as closely as possible, in an effort to
268-
# clean up the home directory.
269-
#if [[ "${BASH_COMPLETION_VERSINFO}" != "2" ]] \
270-
# && [[ ! -e "/etc/bash_completion.d/bash_completion.${USER}" ]] \
271-
#; then
272-
# sudo ln -s "${BASH_COMPLETION_USER_FILE}" "/etc/bash_completion.d/bash_completion.${USER}"
273-
#fi
274-
275-
source "/etc/bash_completion"
257+
elif [[ -e "/etc/profile.d/bash_completion.sh" ]]; then
258+
export BASH_COMPLETION_COMPAT_DIR="/etc/bash_completion.d"
259+
source "/etc/profile.d/bash_completion.sh"
276260
fi
277261

278262
##

home/.config/bash-completion/bash_completion

-12
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,6 @@
2121
# @link https://github.com/danemacmillan/dotfiles
2222
# @license MIT
2323

24-
# Pull in bash completion from version 2 location, and have these loaded
25-
# eagerly. Note that this particular file also needs to be either symlinked
26-
# into the v1 path at /etc/bash_completion.d, or a ~/.bash_completion file
27-
# should source this one.
28-
if [[ "${BASH_COMPLETION_VERSINFO}" != "2" ]]; then
29-
if [[ -e "${XDG_DATA_HOME}/bash-completion/completions" ]]; then
30-
for completion_file in "${XDG_DATA_HOME}/bash-completion/completions/"*; do
31-
source "${completion_file}"
32-
done
33-
fi
34-
fi
35-
3624
# Source google-cloud-sdk gcloud utilities
3725
# https://cloud.google.com/sdk/docs/quickstarts
3826
if [[ -f "/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/completion.bash.inc" ]]; then

home/.config/bash_completion

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# See https://github.com/scop/bash-completion/blob/master/doc/bash_completion.txt
2+
3+

0 commit comments

Comments
 (0)