try to simplify the logic: completion/available/pip.completion.bash

pull/1518/head
Hongyi Zhao 2020-03-15 13:42:55 +08:00
parent cfe7166132
commit 23671ef4f3
1 changed files with 21 additions and 12 deletions

View File

@ -36,18 +36,27 @@ function safe_append_prompt_command {
} }
_pip_completion_bash() { #_pip_completion_bash() {
# Based on the _pip_completion function defined by pip completion to determine # # Based on the _pip_completion function defined by pip completion to determine
# whether we should reevaluate the pip completion or not: # # whether we should reevaluate the pip completion or not:
if ! command -v _pip_completion >/dev/null && # if ! command -v _pip_completion >/dev/null &&
( [ -n "$VIRTUAL_ENV" -a -x "$VIRTUAL_ENV/bin/pip" ] || # ( [ -n "$VIRTUAL_ENV" -a -x "$VIRTUAL_ENV/bin/pip" ] ||
[ -n "$CONDA_PREFIX" -a -x "$CONDA_PREFIX/bin/pip" ] || # [ -n "$CONDA_PREFIX" -a -x "$CONDA_PREFIX/bin/pip" ] ||
[ -x /usr/bin/pip ] ); then # [ -x /usr/bin/pip ] ); then
eval "$(pip completion --bash)" # eval "$(pip completion --bash)"
fi # fi
#}
#safe_append_prompt_command _pip_completion_bash
# pip bash completion start
_pip_completion()
{
COMPREPLY=( $( COMP_WORDS="${COMP_WORDS[*]}" \
COMP_CWORD=$COMP_CWORD \
PIP_AUTO_COMPLETE=1 $1 2>/dev/null ) )
} }
complete -o default -F _pip_completion pip
safe_append_prompt_command _pip_completion_bash # pip bash completion end