From b893ce6f79774188423438f355530311e794f85d Mon Sep 17 00:00:00 2001 From: M Date: Sun, 23 Jan 2022 12:27:11 -0800 Subject: [PATCH] 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 ae532c8..8efbeea 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 ebce13a..5009864 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 8daab5e..95a464b 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 8780e03..58b902a 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 ef8a341..1393587 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 b0357e5..94aaf1d 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 f468341..22369e2 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 a66b98d..773c093 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