From 42bdfeeb6a0fa9bf241800ad6abd4e3cc0f9c5b2 Mon Sep 17 00:00:00 2001 From: Hongyi Zhao Date: Sun, 15 Mar 2020 14:22:30 +0800 Subject: [PATCH] combine the pip completion code into one script. --- completion/available/pip.completion.bash | 53 ++--------------------- completion/available/pip3.completion.bash | 53 ----------------------- 2 files changed, 4 insertions(+), 102 deletions(-) delete mode 100644 completion/available/pip3.completion.bash diff --git a/completion/available/pip.completion.bash b/completion/available/pip.completion.bash index c0638e76..dbc1529f 100644 --- a/completion/available/pip.completion.bash +++ b/completion/available/pip.completion.bash @@ -1,53 +1,8 @@ # https://pip.pypa.io/en/stable/user_guide/#command-completion -# Of course, you should first install the pip, say on Debian: -# sudo apt-get install python-pip -# sudo apt-get install python3-pip -# If the pip package is installed within virtual environments, -# you should first install pip for the corresponding environment. - -#https://github.com/Bash-it/bash-it/blob/b35d41464c0bd390e573f7423eaaa63666521c70/themes/base.theme.bash#L511 -function safe_append_prompt_command { - local prompt_re - - if [ "${__bp_imported}" == "defined" ]; then - # We are using bash-preexec - if ! __check_precmd_conflict "${1}" ; then - precmd_functions+=("${1}") - fi - else - # Set OS dependent exact match regular expression - if [[ ${OSTYPE} == darwin* ]]; then - # macOS - prompt_re="[[:<:]]${1}[[:>:]]" - else - # Linux, FreeBSD, etc. - prompt_re="\<${1}\>" - fi - - if [[ ${PROMPT_COMMAND} =~ ${prompt_re} ]]; then - return - elif [[ -z ${PROMPT_COMMAND} ]]; then - PROMPT_COMMAND="${1}" - else - PROMPT_COMMAND="${1};${PROMPT_COMMAND}" - fi - fi -} - - -#_pip_completion_bash() { -# # Based on the _pip_completion function defined by pip completion to determine -# # whether we should reevaluate the pip completion or not: -# if ! command -v _pip_completion >/dev/null && -# ( [ -n "$VIRTUAL_ENV" -a -x "$VIRTUAL_ENV/bin/pip" ] || -# [ -n "$CONDA_PREFIX" -a -x "$CONDA_PREFIX/bin/pip" ] || -# [ -x /usr/bin/pip ] ); then -# eval "$(pip completion --bash)" -# fi -#} - -#safe_append_prompt_command _pip_completion_bash +# Use the following commands to obtain these completion codes: +#pip completion --bash +#pip3 completion --bash # pip bash completion start _pip_completion() @@ -57,6 +12,6 @@ _pip_completion() PIP_AUTO_COMPLETE=1 $1 2>/dev/null ) ) } complete -o default -F _pip_completion pip +complete -o default -F _pip_completion pip3 # pip bash completion end - diff --git a/completion/available/pip3.completion.bash b/completion/available/pip3.completion.bash deleted file mode 100644 index c5f012a6..00000000 --- a/completion/available/pip3.completion.bash +++ /dev/null @@ -1,53 +0,0 @@ -# https://pip.pypa.io/en/stable/user_guide/#command-completion -# Of course, you should first install the pip, say on Debian: -# sudo apt-get install python-pip -# sudo apt-get install python3-pip - -# If the pip package is installed within virtual environments, -# you should first install pip for the corresponding environment. - -#https://github.com/Bash-it/bash-it/blob/b35d41464c0bd390e573f7423eaaa63666521c70/themes/base.theme.bash#L511 -function safe_append_prompt_command { - local prompt_re - - if [ "${__bp_imported}" == "defined" ]; then - # We are using bash-preexec - if ! __check_precmd_conflict "${1}" ; then - precmd_functions+=("${1}") - fi - else - # Set OS dependent exact match regular expression - if [[ ${OSTYPE} == darwin* ]]; then - # macOS - prompt_re="[[:<:]]${1}[[:>:]]" - else - # Linux, FreeBSD, etc. - prompt_re="\<${1}\>" - fi - - if [[ ${PROMPT_COMMAND} =~ ${prompt_re} ]]; then - return - elif [[ -z ${PROMPT_COMMAND} ]]; then - PROMPT_COMMAND="${1}" - else - PROMPT_COMMAND="${1};${PROMPT_COMMAND}" - fi - fi -} - - -_pip_completion_bash() { - # Based on the _pip_completion function defined by pip completion to determine - # whether we should reevaluate the pip completion or not: - if ! command -v _pip_completion >/dev/null && - ( [ -n "$VIRTUAL_ENV" -a -x "$VIRTUAL_ENV/bin/pip3" ] || - [ -n "$CONDA_PREFIX" -a -x "$CONDA_PREFIX/bin/pip3" ] || - [ -x /usr/bin/pip3 ] ); then - eval "$(pip3 completion --bash)" - fi -} - -safe_append_prompt_command _pip_completion_bash - - -