From b897c7d3ce5a7ca5198ab05a6489c556b19f3d0f Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 23 Sep 2021 22:21:02 -0700 Subject: [PATCH] completion/pip: simplify code flow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Short-circuit the loader rather than indenting nearly the whole file. ALSÖ, assign the `_pip_completion()` handler directly once it's loaded so that we get out of the way once we load it. --- completion/available/pip.completion.bash | 23 ++++++++++++----------- completion/available/pip3.completion.bash | 23 ++++++++++++----------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/completion/available/pip.completion.bash b/completion/available/pip.completion.bash index a20df4cd..f094d6ed 100644 --- a/completion/available/pip.completion.bash +++ b/completion/available/pip.completion.bash @@ -6,14 +6,15 @@ # If the pip package is installed within virtual environments, say, python managed by pyenv, # you should first initialize the corresponding environment. # So that pip is in the system's path. -if _command_exists pip; then - function __bash_it_complete_pip() { - if _command_exists _pip_completion; then - _pip_completion "$@" - else - eval "$(pip completion --bash)" - _pip_completion "$@" - fi - } - complete -o default -F __bash_it_complete_pip pip -fi +_command_exists pip || return + +function __bash_it_complete_pip() { + if _command_exists _pip_completion; then + complete -o default -F _pip_completion pip + _pip_completion "$@" + else + eval "$(pip completion --bash)" + _pip_completion "$@" + fi +} +complete -o default -F __bash_it_complete_pip pip diff --git a/completion/available/pip3.completion.bash b/completion/available/pip3.completion.bash index d69460a5..34abc053 100644 --- a/completion/available/pip3.completion.bash +++ b/completion/available/pip3.completion.bash @@ -6,14 +6,15 @@ # If the pip package is installed within virtual environments, say, python managed by pyenv, # you should first initialize the corresponding environment. # So that pip3 is in the system's path. -if _command_exists pip3; then - function __bash_it_complete_pip3() { - if _command_exists _pip_completion; then - _pip_completion "$@" - else - eval "$(pip3 completion --bash)" - _pip_completion "$@" - fi - } - complete -o default -F __bash_it_complete_pip3 pip3 -fi +_command_exists pip3 || return + +function __bash_it_complete_pip3() { + if _command_exists _pip_completion; then + complete -o default -F _pip_completion pip3 + _pip_completion "$@" + else + eval "$(pip3 completion --bash)" + _pip_completion "$@" + fi +} +complete -o default -F __bash_it_complete_pip3 pip3