Skip to content

Commit

Permalink
feat(completions/system): integrate bash-completion loader in lib/bou…
Browse files Browse the repository at this point in the history
…rne-shell

The search that has been in lib/bourne-shell.sh is slightly different
from that in completions/system.completion.sh.  We integrate the
former into the latter.

* We add a search location
  `/usr/share/bash-completion/bash_completion` for bash-completion.
  This is the standard location for bash-completion v2.  We have been
  only checking /etc/bash_completion which is bash-completion v1.

* We also add a guard for the POSIX mode.  Older versions of
  bash-completion have an issue with the POSIX mode.  In particular,
  bash-completion v1 can only be used with with the macOS Bash 3.2,
  but bash-completion v1 does not work well in the POSIX mode.

* We also add a guard for already loaded bash-completion.  Other
  system configuration might already load bash-completion.  We skip
  loading bash-completion when we detect an existing bash-completion
  settings in tbe current shell environment.
  • Loading branch information
akinomyoga committed May 16, 2024
1 parent fcce66a commit d291140
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion completions/system.completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

# Loads one of the system's Bash-completion modules.

# If bash-completion is already enabled (by e.g. /etc/bash.bashrc sourced from
# /etc/profile or directly executed by Bash), we skip loading bash-completion.
[[ ${BASH_COMPLETION_VERSINFO-} ]] && return 0

# We skip loading bash-completion in the POSIX mode. Older versions of
# bash-completion do not work in the POSIX mode.
shopt -oq posix && return 0

# If Homebrew is installed (OS X), its Bash completion module is loaded.
if is_os darwin && _omb_util_command_exists brew; then
BREW_PREFIX=$(brew --prefix)
Expand All @@ -19,7 +27,12 @@ if is_os darwin && _omb_util_command_exists brew; then
fi
fi

if [[ -f /etc/bash_completion ]]; then
if [[ -f /usr/share/bash-completion/bash_completion ]]; then
# bash-completion v2 is installed at this location
source /usr/share/bash-completion/bash_completion
return "$?"
elif [[ -f /etc/bash_completion ]]; then
# bash-completion v1 is installed at this location
source /etc/bash_completion
return "$?"
fi
Expand Down

0 comments on commit d291140

Please sign in to comment.