From 4fb778c4055b55b3f43683813fd4b2c2c3d98891 Mon Sep 17 00:00:00 2001 From: M Date: Fri, 24 Sep 2021 04:29:09 -0700 Subject: [PATCH 1/7] Refactor "{{which,command -v} => _omb_util_{binary,command}_exists}" `which` has been deprecated in Debian (at least, the rolling release installed on chromebooks via Linux Containers) https://github.com/ohmybash/oh-my-bash/pull/239#issuecomment-1000974461 Co-authored-by: Koichi Murase --- completions/awscli.completion.sh | 2 +- completions/conda.completion.sh | 2 +- completions/django.completion.sh | 2 +- completions/docker.completion.sh | 2 +- completions/drush.completion.sh | 2 +- completions/fabric-completion.sh | 2 +- completions/jungle.completion.sh | 2 +- completions/kontena.completion.sh | 2 +- completions/kubectl.completion.sh | 2 +- completions/minikube.completion.sh | 2 +- completions/npm.completion.sh | 2 +- completions/system.completion.sh | 2 +- lib/base.sh | 4 ++-- lib/misc.sh | 2 +- lib/omb-prompt-base.sh | 4 ++-- themes/brainy/brainy.theme.sh | 4 ++-- tools/autossh.sh | 2 +- 17 files changed, 20 insertions(+), 20 deletions(-) diff --git a/completions/awscli.completion.sh b/completions/awscli.completion.sh index 85777fe39..4495c211f 100644 --- a/completions/awscli.completion.sh +++ b/completions/awscli.completion.sh @@ -1,2 +1,2 @@ #! bash oh-my-bash.module -[[ -x "$(which aws_completer)" ]] &>/dev/null && complete -C "$(which aws_completer)" aws +_omb_util_binary_exists aws_completer && complete -C "$(type -P aws_completer)" aws diff --git a/completions/conda.completion.sh b/completions/conda.completion.sh index e43f8ff74..29222d8d6 100644 --- a/completions/conda.completion.sh +++ b/completions/conda.completion.sh @@ -1,4 +1,4 @@ #! bash oh-my-bash.module -which register-python-argcomplete &> /dev/null \ +_omb_util_binary_exists register-python-argcomplete \ && eval "$(register-python-argcomplete conda)" \ || echo "Please install argcomplete to use conda completion" > /dev/null diff --git a/completions/django.completion.sh b/completions/django.completion.sh index e35dd1ea3..24a5b7353 100644 --- a/completions/django.completion.sh +++ b/completions/django.completion.sh @@ -59,7 +59,7 @@ _python_django_completion() # Support for multiple interpreters. unset pythons -if command -v whereis &>/dev/null; then +if _omb_util_command_exists whereis; then python_interpreters=$(whereis python | cut -d " " -f 2-) for python in $python_interpreters; do pythons="${pythons} $(basename -- $python)" diff --git a/completions/docker.completion.sh b/completions/docker.completion.sh index e34d23757..8daab5e27 100644 --- a/completions/docker.completion.sh +++ b/completions/docker.completion.sh @@ -410,7 +410,7 @@ __docker_nospace() { } __docker_complete_resolved_hostname() { - command -v host >/dev/null 2>&1 || return + _omb_util_command_exists host || return COMPREPLY=( $(host 2>/dev/null "${cur%:}" | awk '/has address/ {print $4}') ) } diff --git a/completions/drush.completion.sh b/completions/drush.completion.sh index 29205c18a..b3232e0f5 100644 --- a/completions/drush.completion.sh +++ b/completions/drush.completion.sh @@ -7,7 +7,7 @@ # http://github.com/drush-ops/drush/blob/master/drush.complete.sh # Ensure drush is available. -which drush &> /dev/null || alias drush &> /dev/null || return +_omb_util_command_exists drush || return __drush_ps1() { f="${TMPDIR:-/tmp/}/drush-env/drush-drupal-site-$$" diff --git a/completions/fabric-completion.sh b/completions/fabric-completion.sh index 2de2a9de0..4653a460d 100644 --- a/completions/fabric-completion.sh +++ b/completions/fabric-completion.sh @@ -80,7 +80,7 @@ function __fab_fabfile_mtime() { # function __fab_completion() { # Return if "fab" command doesn't exists - [[ -e `which fab 2> /dev/null` ]] || return 0 + _omb_util_binary_exists fab || return 0 # Variables to hold the current word and possible matches local cur="${COMP_WORDS[COMP_CWORD]}" diff --git a/completions/jungle.completion.sh b/completions/jungle.completion.sh index d682bb682..c5d419c0a 100644 --- a/completions/jungle.completion.sh +++ b/completions/jungle.completion.sh @@ -1,2 +1,2 @@ #! bash oh-my-bash.module -[[ -x "$(which jungle)" ]] &>/dev/null && eval "$(_JUNGLE_COMPLETE=source jungle)" +_omb_util_binary_exists jungle && eval "$(_JUNGLE_COMPLETE=source jungle)" diff --git a/completions/kontena.completion.sh b/completions/kontena.completion.sh index 67c4ad083..e8aac8822 100644 --- a/completions/kontena.completion.sh +++ b/completions/kontena.completion.sh @@ -1,2 +1,2 @@ #! bash oh-my-bash.module -which kontena &> /dev/null && . "$( kontena whoami --bash-completion-path )" +_omb_util_binary_exists kontena && . "$( kontena whoami --bash-completion-path )" diff --git a/completions/kubectl.completion.sh b/completions/kubectl.completion.sh index 63fd04579..a828c244b 100644 --- a/completions/kubectl.completion.sh +++ b/completions/kubectl.completion.sh @@ -2,7 +2,7 @@ # kubectl (Kubernetes CLI) completion -if command -v kubectl &>/dev/null +if _omb_util_command_exists kubectl then eval "$(kubectl completion bash)" fi diff --git a/completions/minikube.completion.sh b/completions/minikube.completion.sh index 73d2cc068..2509c2e99 100644 --- a/completions/minikube.completion.sh +++ b/completions/minikube.completion.sh @@ -2,7 +2,7 @@ # minikube (Kubernetes CLI) completion -if command -v minikube &>/dev/null +if _omb_util_command_exists minikube then eval "$(minikube completion bash)" fi diff --git a/completions/npm.completion.sh b/completions/npm.completion.sh index 1eb689e85..109460b75 100644 --- a/completions/npm.completion.sh +++ b/completions/npm.completion.sh @@ -3,7 +3,7 @@ # npm (Node Package Manager) completion # https://docs.npmjs.com/cli/completion -if command -v npm &>/dev/null +if _omb_util_command_exists npm then eval "$(npm completion)" fi diff --git a/completions/system.completion.sh b/completions/system.completion.sh index 57a57334b..24743d1b2 100644 --- a/completions/system.completion.sh +++ b/completions/system.completion.sh @@ -13,7 +13,7 @@ if [ -f /etc/profile.d/bash_completion.sh ]; then fi -if [ $(uname) = "Darwin" ] && command -v brew &>/dev/null ; then +if [ $(uname) = "Darwin" ] && _omb_util_command_exists brew; then BREW_PREFIX=$(brew --prefix) if [ -f "$BREW_PREFIX"/etc/bash_completion ]; then diff --git a/lib/base.sh b/lib/base.sh index da7f85734..a9ff6a25f 100644 --- a/lib/base.sh +++ b/lib/base.sh @@ -197,10 +197,10 @@ bigfind() { # ips: display all ip addresses for this host # ------------------------------------------------------------------- ips () { - if command -v ifconfig &>/dev/null + if _omb_util_command_exists ifconfig then ifconfig | awk '/inet /{ print $2 }' - elif command -v ip &>/dev/null + elif _omb_util_command_exists ip then ip addr | grep -oP 'inet \K[\d.]+' else diff --git a/lib/misc.sh b/lib/misc.sh index fb5782c66..53d723280 100644 --- a/lib/misc.sh +++ b/lib/misc.sh @@ -11,7 +11,7 @@ _omb_util_alias _='sudo' _omb_util_alias please='sudo' ## more intelligent acking for ubuntu users -if which ack-grep &> /dev/null; then +if _omb_util_binary_exists ack-grep; then _omb_util_alias afind='ack-grep -il' else _omb_util_alias afind='ack -il' diff --git a/lib/omb-prompt-base.sh b/lib/omb-prompt-base.sh index 447ecb4e2..54ebc279e 100644 --- a/lib/omb-prompt-base.sh +++ b/lib/omb-prompt-base.sh @@ -104,9 +104,9 @@ function _omb_prompt_format { function scm { if [[ "$SCM_CHECK" = false ]]; then SCM=$SCM_NONE elif [[ -f .git/HEAD ]]; then SCM=$SCM_GIT - elif which git &> /dev/null && [[ -n "$(git rev-parse --is-inside-work-tree 2> /dev/null)" ]]; then SCM=$SCM_GIT + elif _omb_util_binary_exists git && [[ -n "$(git rev-parse --is-inside-work-tree 2> /dev/null)" ]]; then SCM=$SCM_GIT elif [[ -d .hg ]]; then SCM=$SCM_HG - elif which hg &> /dev/null && [[ -n "$(hg root 2> /dev/null)" ]]; then SCM=$SCM_HG + elif _omb_util_binary_exists hg && [[ -n "$(hg root 2> /dev/null)" ]]; then SCM=$SCM_HG elif [[ -d .svn ]]; then SCM=$SCM_SVN else SCM=$SCM_NONE fi diff --git a/themes/brainy/brainy.theme.sh b/themes/brainy/brainy.theme.sh index a44a267e4..6a96ff760 100644 --- a/themes/brainy/brainy.theme.sh +++ b/themes/brainy/brainy.theme.sh @@ -135,8 +135,8 @@ ___brainy_prompt_ruby() { } ___brainy_prompt_todo() { - [ "${THEME_SHOW_TODO}" != "true" ] || - [ -z "$(which todo.sh)" ] && return + [ "${THEME_SHOW_TODO}" != "true" ] && return + _omb_util_binary_exists todo.sh || return color=$_omb_prompt_bold_white box="[|]" info="t:$(todo.sh ls | egrep "TODO: [0-9]+ of ([0-9]+)" | awk '{ print $4 }' )" diff --git a/tools/autossh.sh b/tools/autossh.sh index 20712d0ee..409ea7f09 100644 --- a/tools/autossh.sh +++ b/tools/autossh.sh @@ -16,7 +16,7 @@ ALIVE=0 HISTFILE="$HOME/.autossh.history" # Use colors, but only if connected to a terminal, and that terminal supports them. -if which tput >/dev/null 2>&1; then +if type -P tput >/dev/null 2>&1; then ncolors=$(tput colors) fi if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then From b893ce6f79774188423438f355530311e794f85d Mon Sep 17 00:00:00 2001 From: M Date: Sun, 23 Jan 2022 12:27:11 -0800 Subject: [PATCH 2/7] Refactor "{declare -{f,F} => _omb_util_function_exists}" Co-authored-by: Koichi Murase --- completions/docker-compose.completion.sh | 2 +- completions/docker-machine.completion.sh | 2 +- completions/docker.completion.sh | 4 ++-- completions/gh.completion.sh | 2 +- completions/hub.completion.sh | 4 ++-- completions/maven.completion.sh | 4 ++-- completions/packer.completion.sh | 4 ++-- themes/dulcie/dulcie.theme.sh | 2 +- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/completions/docker-compose.completion.sh b/completions/docker-compose.completion.sh index ae532c861..8efbeeaa1 100644 --- a/completions/docker-compose.completion.sh +++ b/completions/docker-compose.completion.sh @@ -552,7 +552,7 @@ _docker_compose() { done local completions_func=_docker_compose_${command//-/_} - declare -F $completions_func >/dev/null && $completions_func + _omb_util_function_exists $completions_func && $completions_func eval "$previous_extglob_setting" return 0 diff --git a/completions/docker-machine.completion.sh b/completions/docker-machine.completion.sh index ebce13a21..500986420 100644 --- a/completions/docker-machine.completion.sh +++ b/completions/docker-machine.completion.sh @@ -243,7 +243,7 @@ _docker_machine() { done local completion_func=_docker_machine_"${command//-/_}" - if declare -F "${completion_func}" > /dev/null; then + if _omb_util_function_exists "${completion_func}"; then ${completion_func} fi diff --git a/completions/docker.completion.sh b/completions/docker.completion.sh index 8daab5e27..95a464b3a 100644 --- a/completions/docker.completion.sh +++ b/completions/docker.completion.sh @@ -394,7 +394,7 @@ __docker_subcommands() { subcommand_pos=$counter local subcommand=${words[$counter]} local completions_func=_docker_${command}_${subcommand} - declare -F $completions_func >/dev/null && $completions_func + _omb_util_function_exists $completions_func && $completions_func return 0 ;; esac @@ -2953,7 +2953,7 @@ _docker() { fi local completions_func=_docker_${command} - declare -F $completions_func >/dev/null && $completions_func + _omb_util_function_exists $completions_func && $completions_func eval "$previous_extglob_setting" return 0 diff --git a/completions/gh.completion.sh b/completions/gh.completion.sh index 8780e0311..58b902aaa 100644 --- a/completions/gh.completion.sh +++ b/completions/gh.completion.sh @@ -3,7 +3,7 @@ # This script complements the completion script that ships with git. # Check that git tab completion is available -if declare -F _git > /dev/null; then +if _omb_util_function_exists _git; then # Duplicate and rename the 'list_all_commands' function eval "$(declare -f __git_list_all_commands | \ sed 's/__git_list_all_commands/__git_list_all_commands_without_hub/')" diff --git a/completions/hub.completion.sh b/completions/hub.completion.sh index ef8a34197..1393587f5 100644 --- a/completions/hub.completion.sh +++ b/completions/hub.completion.sh @@ -3,12 +3,12 @@ # This script complements the completion script that ships with git. # If there is no git tab completion, but we have the _completion loader try to load it -if ! declare -F _git > /dev/null && declare -F _completion_loader > /dev/null; then +if ! _omb_util_function_exists _git && _omb_util_function_exists _completion_loader; then _completion_loader git fi # Check that git tab completion is available -if declare -F _git > /dev/null; then +if _omb_util_function_exists _git; then # Duplicate and rename the 'list_all_commands' function eval "$(declare -f __git_list_all_commands | \ sed 's/__git_list_all_commands/__git_list_all_commands_without_hub/')" diff --git a/completions/maven.completion.sh b/completions/maven.completion.sh index b0357e507..94aaf1df9 100644 --- a/completions/maven.completion.sh +++ b/completions/maven.completion.sh @@ -6,7 +6,7 @@ function_exists() { - declare -F $1 > /dev/null + _omb_util_function_exists $1 return $? } @@ -261,4 +261,4 @@ _mvn() } complete -o default -F _mvn -o nospace mvn -complete -o default -F _mvn -o nospace mvnDebug \ No newline at end of file +complete -o default -F _mvn -o nospace mvnDebug diff --git a/completions/packer.completion.sh b/completions/packer.completion.sh index f4683416e..22369e275 100644 --- a/completions/packer.completion.sh +++ b/completions/packer.completion.sh @@ -130,7 +130,7 @@ _packer_completion () # Words containing an equal sign get split into tokens in bash > 4, which # doesn't come in handy here. # This is handled here. bash < 4 does not split. - declare -f _get_comp_words_by_ref >/dev/null && _get_comp_words_by_ref -n = cur + _omb_util_function_exists _get_comp_words_by_ref && _get_comp_words_by_ref -n = cur COMPREPLY=() local i c=1 command @@ -157,7 +157,7 @@ _packer_completion () fi local completion_func="__packer_${command}" - declare -f $completion_func >/dev/null && $completion_func + _omb_util_function_exists $completion_func && $completion_func } complete -o nospace -F _packer_completion packer diff --git a/themes/dulcie/dulcie.theme.sh b/themes/dulcie/dulcie.theme.sh index a66b98d6e..773c09353 100644 --- a/themes/dulcie/dulcie.theme.sh +++ b/themes/dulcie/dulcie.theme.sh @@ -77,7 +77,7 @@ _omb_theme_PROMPT_COMMAND() { printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}" # Open the new terminal in the same directory - declare -f __vte_osc7 > /dev/null && __vte_osc7 + _omb_util_function_exists __vte_osc7 && __vte_osc7 PS1="${_omb_prompt_reset_color}[${DULCIE_USER}@${DULCIE_HOST}$(scm_prompt_info)${_omb_prompt_reset_color} ${DULCIE_WORKINGDIR}]" if [[ "${DULCIE_MULTILINE}" -eq "1" ]]; then From de66a70f91e24ca422fbb382bbf3c39a7ec21090 Mon Sep 17 00:00:00 2001 From: M Date: Sun, 23 Jan 2022 12:29:59 -0800 Subject: [PATCH 3/7] Refactor "{ => _omb_util_}command_exists" https://github.com/ohmybash/oh-my-bash/pull/239#issuecomment-1007886245 Co-authored-by: Koichi Murase --- lib/base.sh | 6 ------ plugins/battery/battery.plugin.sh | 33 ++++++++++++++----------------- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/lib/base.sh b/lib/base.sh index a9ff6a25f..b7efca621 100644 --- a/lib/base.sh +++ b/lib/base.sh @@ -272,12 +272,6 @@ bigfind() { fi } -# command_exists: checks for existence of a command (0 = true, 1 = false) -# ------------------------------------------------------------------- - command_exists () { - type "$1" &> /dev/null ; - } - # pickfrom: picks random line from file # ------------------------------------------------------------------- pickfrom () { diff --git a/plugins/battery/battery.plugin.sh b/plugins/battery/battery.plugin.sh index db514a645..fde8ee095 100644 --- a/plugins/battery/battery.plugin.sh +++ b/plugins/battery/battery.plugin.sh @@ -1,30 +1,27 @@ #! bash oh-my-bash.module -# Bug: https://github.com/ohmybash/oh-my-bash/issues/68 -if ! command -v "command_exists" >/dev/null; then command_exists() { command -v "$1" >/dev/null ; } fi - _omb_plugin_battery__upower_print_info() { upower -i "$(upower -e | sed -n '/BAT/{p;q;}')" } ac_adapter_connected(){ - if command_exists upower; + if _omb_util_command_exists upower; then _omb_plugin_battery__upower_print_info | grep -qE 'state[:[:blank:]]*(charging|fully-charged)' return $? - elif command_exists acpi; + elif _omb_util_command_exists acpi; then acpi -a | grep -q "on-line" return $? - elif command_exists pmset; + elif _omb_util_command_exists pmset; then pmset -g batt | grep -q 'AC Power' return $? - elif command_exists ioreg; + elif _omb_util_command_exists ioreg; then ioreg -n AppleSmartBattery -r | grep -q '"ExternalConnected" = Yes' return $? - elif command_exists WMIC; + elif _omb_util_command_exists WMIC; then WMIC Path Win32_Battery Get BatteryStatus /Format:List | grep -q 'BatteryStatus=2' return $? @@ -32,23 +29,23 @@ ac_adapter_connected(){ } ac_adapter_disconnected(){ - if command_exists upower; + if _omb_util_command_exists upower; then _omb_plugin_battery__upower_print_info | grep -qE 'state[:[:blank:]]*discharging' return $? - elif command_exists acpi; + elif _omb_util_command_exists acpi; then acpi -a | grep -q "off-line" return $? - elif command_exists pmset; + elif _omb_util_command_exists pmset; then pmset -g batt | grep -q 'Battery Power' return $? - elif command_exists ioreg; + elif _omb_util_command_exists ioreg; then ioreg -n AppleSmartBattery -r | grep -q '"ExternalConnected" = No' return $? - elif command_exists WMIC; + elif _omb_util_command_exists WMIC; then WMIC Path Win32_Battery Get BatteryStatus /Format:List | grep -q 'BatteryStatus=1' return $? @@ -59,12 +56,12 @@ ac_adapter_disconnected(){ ## @about 'displays battery charge as a percentage of full (100%)' ## @group 'battery' battery_percentage(){ - if command_exists upower; + if _omb_util_command_exists upower; then local UPOWER_OUTPUT=$(_omb_plugin_battery__upower_print_info | sed -n 's/.*percentage[:[:blank:]]*\([0-9%]\{1,\}\)$/\1/p') [[ $UPOWER_OUTPUT ]] && echo "${UPOWER_OUTPUT::-1}" - elif command_exists acpi; + elif _omb_util_command_exists acpi; then local ACPI_OUTPUT=$(acpi -b) case $ACPI_OUTPUT in @@ -91,7 +88,7 @@ battery_percentage(){ echo '-1' ;; esac - elif command_exists pmset; + elif _omb_util_command_exists pmset; then local PMSET_OUTPUT=$(pmset -g ps | sed -n 's/.*[[:blank:]]+*\(.*%\).*/\1/p') case $PMSET_OUTPUT in @@ -102,7 +99,7 @@ battery_percentage(){ echo $PMSET_OUTPUT | head -c 2 ;; esac - elif command_exists ioreg; + elif _omb_util_command_exists ioreg; then local IOREG_OUTPUT=$(ioreg -n AppleSmartBattery -r | awk '$1~/Capacity/{c[$1]=$3} END{OFMT="%05.2f%%"; max=c["\"MaxCapacity\""]; print (max>0? 100*c["\"CurrentCapacity\""]/max: "?")}') case $IOREG_OUTPUT in @@ -113,7 +110,7 @@ battery_percentage(){ echo $IOREG_OUTPUT | head -c 2 ;; esac - elif command_exists WMIC; + elif _omb_util_command_exists WMIC; then local WINPC=$(echo porcent=$(WMIC PATH Win32_Battery Get EstimatedChargeRemaining /Format:List) | grep -o '[0-9]*') case $WINPC in From 2202aeeb044bc5f00d6d52628b155c00c1db4494 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Tue, 23 Aug 2022 17:42:39 +0900 Subject: [PATCH 4/7] Refactor "{type => _omb_util_command_exists}" --- completions/docker-compose.completion.sh | 2 +- completions/docker.completion.sh | 2 +- lib/base.sh | 2 +- lib/utils.sh | 2 +- plugins/nvm/nvm.plugin.sh | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/completions/docker-compose.completion.sh b/completions/docker-compose.completion.sh index 8efbeeaa1..be58a51f7 100644 --- a/completions/docker-compose.completion.sh +++ b/completions/docker-compose.completion.sh @@ -39,7 +39,7 @@ __docker_compose_to_extglob() { # suppress trailing whitespace __docker_compose_nospace() { # compopt is not available in ancient bash versions - type compopt &>/dev/null && compopt -o nospace + _omb_util_command_exists compopt && compopt -o nospace } # Extracts all service names from the compose file. diff --git a/completions/docker.completion.sh b/completions/docker.completion.sh index 95a464b3a..c14c600b3 100644 --- a/completions/docker.completion.sh +++ b/completions/docker.completion.sh @@ -406,7 +406,7 @@ __docker_subcommands() { # suppress trailing whitespace __docker_nospace() { # compopt is not available in ancient bash versions - type compopt &>/dev/null && compopt -o nospace + _omb_util_command_exists compopt && compopt -o nospace } __docker_complete_resolved_hostname() { diff --git a/lib/base.sh b/lib/base.sh index b7efca621..1a14cc4bd 100644 --- a/lib/base.sh +++ b/lib/base.sh @@ -124,7 +124,7 @@ zipf () { zip -r "$1".zip "$1" ; } # zipf: To create a ZIP arc # mkiso: creates iso from current dir in the parent dir (unless defined) # --------------------------------------------------------- mkiso () { - if type "mkisofs" > /dev/null; then + if _omb_util_command_exists mkisofs; then if [ -z ${1+x} ]; then local isoname=${PWD##*/} else diff --git a/lib/utils.sh b/lib/utils.sh index 9e8750c5d..b6e8c7750 100644 --- a/lib/utils.sh +++ b/lib/utils.sh @@ -403,7 +403,7 @@ _omb_util_alias() { function _omb_util_mktemp { local template=tmp.oh-my-bash.XXXXXXXXXX - if type -t mktemp &>/dev/null; then + if _omb_util_command_exists mktemp; then mktemp -t "$template" else m4 -D template="${TMPDIR:-/tmp}/$template" <<< 'mkstemp(template)' diff --git a/plugins/nvm/nvm.plugin.sh b/plugins/nvm/nvm.plugin.sh index 9cb7c495b..068ce1d2c 100644 --- a/plugins/nvm/nvm.plugin.sh +++ b/plugins/nvm/nvm.plugin.sh @@ -5,7 +5,7 @@ # Try to load nvm only if command not already available -if ! type "nvm" &> /dev/null; then +if ! _omb_util_command_exists nvm; then [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm # This is done as part of completions!!! # [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion From d5e9c7deb10df1bf2724383fa21c8f89c9e63504 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Tue, 23 Aug 2022 17:47:35 +0900 Subject: [PATCH 5/7] tools/install: Refactor "{hash => type -P}" --- tools/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/install.sh b/tools/install.sh index 00b4e73bc..0bb6283c6 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -176,7 +176,7 @@ _omb_install_system_bashrc() { _omb_install_main() { # Use colors, but only if connected to a terminal, and that terminal # supports them. - if hash tput >/dev/null 2>&1; then + if type -P tput &>/dev/null; then local ncolors=$(tput colors 2>/dev/null || tput Co 2>/dev/null || echo -1) fi From e0a4ada27562954061d48719a2a309426f39f022 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Tue, 23 Aug 2022 16:05:56 +0900 Subject: [PATCH 6/7] completions/conda: Fix a discarded warning message --- completions/conda.completion.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/completions/conda.completion.sh b/completions/conda.completion.sh index 29222d8d6..e2dac526c 100644 --- a/completions/conda.completion.sh +++ b/completions/conda.completion.sh @@ -1,4 +1,4 @@ #! bash oh-my-bash.module _omb_util_binary_exists register-python-argcomplete \ && eval "$(register-python-argcomplete conda)" \ - || echo "Please install argcomplete to use conda completion" > /dev/null + || echo "Please install argcomplete to use conda completion" From 49c66cf04ac74c5473b8b2ff951a8e0757498f4b Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Tue, 23 Aug 2022 16:17:42 +0900 Subject: [PATCH 7/7] completions/*: Fix quoting around _omb_util_function_exists --- completions/docker-compose.completion.sh | 2 +- completions/docker-machine.completion.sh | 2 +- completions/docker.completion.sh | 4 ++-- completions/maven.completion.sh | 4 ++-- completions/packer.completion.sh | 6 +++--- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/completions/docker-compose.completion.sh b/completions/docker-compose.completion.sh index be58a51f7..b3fabd860 100644 --- a/completions/docker-compose.completion.sh +++ b/completions/docker-compose.completion.sh @@ -552,7 +552,7 @@ _docker_compose() { done local completions_func=_docker_compose_${command//-/_} - _omb_util_function_exists $completions_func && $completions_func + _omb_util_function_exists "$completions_func" && "$completions_func" eval "$previous_extglob_setting" return 0 diff --git a/completions/docker-machine.completion.sh b/completions/docker-machine.completion.sh index 500986420..c6d0a397c 100644 --- a/completions/docker-machine.completion.sh +++ b/completions/docker-machine.completion.sh @@ -244,7 +244,7 @@ _docker_machine() { local completion_func=_docker_machine_"${command//-/_}" if _omb_util_function_exists "${completion_func}"; then - ${completion_func} + "${completion_func}" fi return 0 diff --git a/completions/docker.completion.sh b/completions/docker.completion.sh index c14c600b3..6b3d8c115 100644 --- a/completions/docker.completion.sh +++ b/completions/docker.completion.sh @@ -394,7 +394,7 @@ __docker_subcommands() { subcommand_pos=$counter local subcommand=${words[$counter]} local completions_func=_docker_${command}_${subcommand} - _omb_util_function_exists $completions_func && $completions_func + _omb_util_function_exists "$completions_func" && "$completions_func" return 0 ;; esac @@ -2953,7 +2953,7 @@ _docker() { fi local completions_func=_docker_${command} - _omb_util_function_exists $completions_func && $completions_func + _omb_util_function_exists "$completions_func" && "$completions_func" eval "$previous_extglob_setting" return 0 diff --git a/completions/maven.completion.sh b/completions/maven.completion.sh index 94aaf1df9..a5d36c680 100644 --- a/completions/maven.completion.sh +++ b/completions/maven.completion.sh @@ -6,8 +6,8 @@ function_exists() { - _omb_util_function_exists $1 - return $? + _omb_util_function_exists "$1" + return "$?" } function_exists _get_comp_words_by_ref || diff --git a/completions/packer.completion.sh b/completions/packer.completion.sh index 22369e275..d2ac8e054 100644 --- a/completions/packer.completion.sh +++ b/completions/packer.completion.sh @@ -133,7 +133,7 @@ _packer_completion () _omb_util_function_exists _get_comp_words_by_ref && _get_comp_words_by_ref -n = cur COMPREPLY=() - local i c=1 command + local i c=1 command= while [ $c -lt $COMP_CWORD ]; do i="${COMP_WORDS[c]}" @@ -144,7 +144,7 @@ _packer_completion () ((c++)) done - if [ -z $command ]; then + if [ -z "$command" ]; then case "$cur" in '-'*) __packercomp "-machine-readable --help --version" @@ -157,7 +157,7 @@ _packer_completion () fi local completion_func="__packer_${command}" - _omb_util_function_exists $completion_func && $completion_func + _omb_util_function_exists "$completion_func" && "$completion_func" } complete -o nospace -F _packer_completion packer