Based on the _pip_completion function defined by pip completion to determine
whether we should reevaluate the pip completion or not.pull/1518/head
parent
db64f5521c
commit
cfe7166132
|
|
@ -6,8 +6,6 @@
|
||||||
# If the pip package is installed within virtual environments,
|
# If the pip package is installed within virtual environments,
|
||||||
# you should first install pip for the corresponding environment.
|
# you should first install pip for the corresponding environment.
|
||||||
|
|
||||||
# Fix pip completion for running it within/outside of pyenv/virtualenv/venv/conda environment.
|
|
||||||
|
|
||||||
#https://github.com/Bash-it/bash-it/blob/b35d41464c0bd390e573f7423eaaa63666521c70/themes/base.theme.bash#L511
|
#https://github.com/Bash-it/bash-it/blob/b35d41464c0bd390e573f7423eaaa63666521c70/themes/base.theme.bash#L511
|
||||||
function safe_append_prompt_command {
|
function safe_append_prompt_command {
|
||||||
local prompt_re
|
local prompt_re
|
||||||
|
|
@ -39,26 +37,17 @@ function safe_append_prompt_command {
|
||||||
|
|
||||||
|
|
||||||
_pip_completion_bash() {
|
_pip_completion_bash() {
|
||||||
local _pip
|
# Based on the _pip_completion function defined by pip completion to determine
|
||||||
# For pip resides within the pyenv/virtualenv/venv/conda environments:
|
# whether we should reevaluate the pip completion or not:
|
||||||
if [ -n "$VIRTUAL_ENV" ] && [ -x "$VIRTUAL_ENV/bin/pip" ]; then
|
if ! command -v _pip_completion >/dev/null &&
|
||||||
_pip="$VIRTUAL_ENV/bin/pip"
|
( [ -n "$VIRTUAL_ENV" -a -x "$VIRTUAL_ENV/bin/pip" ] ||
|
||||||
elif [ -n "$CONDA_PREFIX" ] && [ -x "$CONDA_PREFIX/bin/pip" ]; then
|
[ -n "$CONDA_PREFIX" -a -x "$CONDA_PREFIX/bin/pip" ] ||
|
||||||
_pip="$CONDA_PREFIX/bin/pip"
|
[ -x /usr/bin/pip ] ); then
|
||||||
# For pip resides outside of a virtual environment:
|
eval "$(pip completion --bash)"
|
||||||
elif [ -x /usr/bin/pip ]; then
|
|
||||||
_pip=/usr/bin/pip
|
|
||||||
fi
|
|
||||||
# FIXME: do the trick without exporting variable into environment:
|
|
||||||
if [ -n "$_pip" ]; then
|
|
||||||
if [ -z "$_pip_command_path" ] || [ "$_pip_command_path" != "$_pip" ]; then
|
|
||||||
eval "$($_pip completion --bash)"
|
|
||||||
export _pip_command_path=$_pip
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
unset _pip
|
|
||||||
}
|
}
|
||||||
|
|
||||||
safe_append_prompt_command _pip_completion_bash
|
safe_append_prompt_command _pip_completion_bash
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,6 @@
|
||||||
# If the pip package is installed within virtual environments,
|
# If the pip package is installed within virtual environments,
|
||||||
# you should first install pip for the corresponding environment.
|
# you should first install pip for the corresponding environment.
|
||||||
|
|
||||||
# Fix pip completion for running it within/outside of pyenv/virtualenv/venv/conda environment.
|
|
||||||
|
|
||||||
#https://github.com/Bash-it/bash-it/blob/b35d41464c0bd390e573f7423eaaa63666521c70/themes/base.theme.bash#L511
|
#https://github.com/Bash-it/bash-it/blob/b35d41464c0bd390e573f7423eaaa63666521c70/themes/base.theme.bash#L511
|
||||||
function safe_append_prompt_command {
|
function safe_append_prompt_command {
|
||||||
local prompt_re
|
local prompt_re
|
||||||
|
|
@ -39,26 +37,17 @@ function safe_append_prompt_command {
|
||||||
|
|
||||||
|
|
||||||
_pip_completion_bash() {
|
_pip_completion_bash() {
|
||||||
local _pip
|
# Based on the _pip_completion function defined by pip completion to determine
|
||||||
# For pip resides within the pyenv/virtualenv/venv/conda environments:
|
# whether we should reevaluate the pip completion or not:
|
||||||
if [ -n "$VIRTUAL_ENV" ] && [ -x "$VIRTUAL_ENV/bin/pip3" ]; then
|
if ! command -v _pip_completion >/dev/null &&
|
||||||
_pip="$VIRTUAL_ENV/bin/pip3"
|
( [ -n "$VIRTUAL_ENV" -a -x "$VIRTUAL_ENV/bin/pip3" ] ||
|
||||||
elif [ -n "$CONDA_PREFIX" ] && [ -x "$CONDA_PREFIX/bin/pip3" ]; then
|
[ -n "$CONDA_PREFIX" -a -x "$CONDA_PREFIX/bin/pip3" ] ||
|
||||||
_pip="$CONDA_PREFIX/bin/pip3"
|
[ -x /usr/bin/pip3 ] ); then
|
||||||
# For pip resides outside of a virtual environment:
|
eval "$(pip3 completion --bash)"
|
||||||
elif [ -x /usr/bin/pip3 ]; then
|
|
||||||
_pip=/usr/bin/pip3
|
|
||||||
fi
|
|
||||||
# FIXME: do the trick without exporting variable into environment:
|
|
||||||
if [ -n "$_pip" ]; then
|
|
||||||
if [ -z "$_pip_command_path" ] || [ "$_pip_command_path" != "$_pip" ]; then
|
|
||||||
eval "$($_pip completion --bash)"
|
|
||||||
export _pip_command_path=$_pip
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
unset _pip
|
|
||||||
}
|
}
|
||||||
|
|
||||||
safe_append_prompt_command _pip_completion_bash
|
safe_append_prompt_command _pip_completion_bash
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue