diff --git a/completions/system.completion.sh b/completions/system.completion.sh index 24743d1b2..18200b6bb 100644 --- a/completions/system.completion.sh +++ b/completions/system.completion.sh @@ -1,27 +1,44 @@ #! bash oh-my-bash.module -# Loads the system's Bash completion modules. -# If Homebrew is installed (OS X), its Bash completion modules are loaded. +# Loads one of the system's Bash-completion modules. -if [ -f /etc/bash_completion ]; then - . /etc/bash_completion -fi - -# Some distribution makes use of a profile.d script to import completion. -if [ -f /etc/profile.d/bash_completion.sh ]; then - . /etc/profile.d/bash_completion.sh -fi +# 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 [ $(uname) = "Darwin" ] && _omb_util_command_exists brew; then +# 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) - if [ -f "$BREW_PREFIX"/etc/bash_completion ]; then - . "$BREW_PREFIX"/etc/bash_completion + # homebrew/versions/bash-completion2 (required for projects.completion.bash) + # is installed to this path + if [[ -f "$BREW_PREFIX"/share/bash-completion/bash_completion ]]; then + source "$BREW_PREFIX"/share/bash-completion/bash_completion + return "$?" fi - # homebrew/versions/bash-completion2 (required for projects.completion.bash) is installed to this path - if [ -f "$BREW_PREFIX"/share/bash-completion/bash_completion ]; then - . "$BREW_PREFIX"/share/bash-completion/bash_completion + if [[ -f "$BREW_PREFIX"/etc/bash_completion ]]; then + source "$BREW_PREFIX"/etc/bash_completion + return "$?" fi fi + +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 + +if [[ -f /etc/profile.d/bash_completion.sh ]]; then + # Some distribution makes use of a profile.d script to import completion. + source /etc/profile.d/bash_completion.sh + return "$?" +fi diff --git a/lib/base.sh b/lib/base.sh index c9ed54a22..e9d6b4d93 100644 --- a/lib/base.sh +++ b/lib/base.sh @@ -229,9 +229,9 @@ function ii { echo -e "\\n${_omb_term_brown}Users logged on:$NC " ; w -h echo -e "\\n${_omb_term_brown}Current date :$NC " ; date echo -e "\\n${_omb_term_brown}Machine stats :$NC " ; uptime - [[ "$OSTYPE" == darwin* ]] && echo -e "\\n${_omb_term_brown}Current network location :$NC " ; scselect + is_os darwin && echo -e "\\n${_omb_term_brown}Current network location :$NC " ; scselect echo -e "\\n${_omb_term_brown}Public facing IP Address :$NC " ;myip - [[ "$OSTYPE" == darwin* ]] && echo -e "\\n${_omb_term_brown}DNS Configuration:$NC " ; scutil --dns + is_os darwin && echo -e "\\n${_omb_term_brown}DNS Configuration:$NC " ; scutil --dns echo } @@ -257,7 +257,7 @@ function batch_chmod { # usage: disk usage per directory, in Mac OS X and Linux # ------------------------------------------------------------------- function usage { - if [ "$(uname)" = "Darwin" ]; then + if is_os darwin; then if [ -n "$1" ]; then du -hd 1 "$1" else diff --git a/lib/bourne-shell.sh b/lib/bourne-shell.sh index 64499f125..5ec0875f8 100644 --- a/lib/bourne-shell.sh +++ b/lib/bourne-shell.sh @@ -98,14 +98,3 @@ fi if [ -f ~/.bashrc.local ]; then . ~/.bashrc.local fi - -# enable programmable completion features (you don't need to enable -# this, if it's already enabled in /etc/bash.bashrc and /etc/profile -# sources /etc/bash.bashrc). -if ! shopt -oq posix; then - if [ -f /usr/share/bash-completion/bash_completion ]; then - . /usr/share/bash-completion/bash_completion - elif [ -f /etc/bash_completion ]; then - . /etc/bash_completion - fi -fi diff --git a/lib/functions.sh b/lib/functions.sh index 37202690e..7e87d6695 100644 --- a/lib/functions.sh +++ b/lib/functions.sh @@ -31,7 +31,7 @@ function open_command() { esac # don't use nohup on OSX - if [[ "$OSTYPE" == darwin* ]]; then + if is_os darwin; then $open_cmd "$@" &>/dev/null else nohup $open_cmd "$@" &>/dev/null diff --git a/lib/utils.sh b/lib/utils.sh index d2e01b546..c1e83c192 100644 --- a/lib/utils.sh +++ b/lib/utils.sh @@ -40,7 +40,7 @@ # exit 1 # fi -# if is_os "darwin"; then +# if is_os darwin; then # e_success "You are on a mac" # else # e_error "You are not on a mac" @@ -255,7 +255,7 @@ function is_confirmed { # # Test which OS the user runs # $1 = OS to test -# Usage: if is_os 'darwin'; then +# Usage: if is_os darwin; then # function is_os { [[ $OSTYPE == $1* ]] @@ -344,7 +344,7 @@ function _omb_util_add_prompt_command { # Set OS dependent exact match regular expression local prompt_re - if [[ $OSTYPE == darwin* ]]; then + if is_os darwin; then # macOS prompt_re='[[:<:]]'$hook'[[:>:]]' else diff --git a/oh-my-bash.sh b/oh-my-bash.sh index 689a49953..47de61579 100644 --- a/oh-my-bash.sh +++ b/oh-my-bash.sh @@ -117,7 +117,7 @@ _omb_module_require_lib "${_omb_init_files[@]}" unset -v _omb_init_files # Figure out the SHORT hostname -if [[ $OSTYPE = darwin* ]]; then +if is_os darwin; then # macOS's $HOST changes with dhcp, etc. Use ComputerName if possible. SHORT_HOST=$(scutil --get ComputerName 2>/dev/null) || SHORT_HOST=${HOST/.*} else diff --git a/templates/bashrc.osh-template b/templates/bashrc.osh-template index 4f1851d98..ad0d3aab3 100644 --- a/templates/bashrc.osh-template +++ b/templates/bashrc.osh-template @@ -84,6 +84,7 @@ OMB_USE_SUDO=true # Example format: completions=(ssh git bundler gem pip pip3) # Add wisely, as too many completions slow down shell startup. completions=( + system git composer ssh diff --git a/themes/rjorgenson/rjorgenson.theme.sh b/themes/rjorgenson/rjorgenson.theme.sh index 57c37a727..798d86f3a 100644 --- a/themes/rjorgenson/rjorgenson.theme.sh +++ b/themes/rjorgenson/rjorgenson.theme.sh @@ -16,7 +16,7 @@ SCM_SVN_CHAR="${_omb_prompt_bold_teal}⑆${_omb_prompt_normal}" SCM_HG_CHAR="${_omb_prompt_bold_brown}☿${_omb_prompt_normal}" PROMPT_CHAR="${OMB_THEME_BRACKET_COLOR}➞ ${_omb_prompt_normal}" -if [[ $OSTYPE == *darwin* ]]; then +if is_os darwin; then PROMPT_CHAR="${OMB_THEME_BRACKET_COLOR}➞ ${_omb_prompt_normal}" fi