Skip to content
This repository has been archived by the owner on Apr 25, 2021. It is now read-only.

Commit

Permalink
Work around a poetry/pyenv path conflict
Browse files Browse the repository at this point in the history
See python-poetry/poetry#571

Also, fix my prompt in the process
  • Loading branch information
jacobian committed Jun 5, 2019
1 parent 66b3cde commit e7889c5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
26 changes: 12 additions & 14 deletions home/.profile.d/prompt
Expand Up @@ -26,20 +26,18 @@ _lastcommandfailed() {

_virtualenv() {
if [ x$VIRTUAL_ENV != x ]; then
if [[ $VIRTUAL_ENV == */pypoetry/virtualenvs/* ]]; then
ENV_NAME=`basename "${VIRTUAL_ENV}"`
else
folder=`dirname "${VIRTUAL_ENV}"`
ENV_NAME=`basename "$folder"`
if [[ $VIRTUAL_ENV == */pypoetry/virtualenvs/* ]]; then
# If this is a poetry env strip the -xxxx-pyx.y from the end
ENV_NAME=`basename "${VIRTUAL_ENV}" | rev | cut -d- -f3- | rev`
else
folder=`dirname "${VIRTUAL_ENV}"`
ENV_NAME=`basename "$folder"`
fi

echo -n $' \033[37mworkon \033[31m'
echo -n $ENV_NAME
echo -n $'\033[00m'
fi
echo -n $' \033[37mworkon \033[31m'
echo -n $ENV_NAME
echo -n $'\033[00m'
# Shell title
echo -n $'\033]0;venv:'
echo -n $ENV_NAME
echo -n $'\007'
fi
}

function _clr {
Expand All @@ -55,7 +53,7 @@ function _bg {
export BASEPROMPT="\n\$(_lastcommandfailed)\
$(_fg $GREEN)\w\
$(_fg $GRAY)\$(_vcprompt)\
$(_virtualenv)\
\$(_virtualenv)\
$(_clr)"
export PS1="${BASEPROMPT}
$ "
Expand Down
19 changes: 18 additions & 1 deletion home/.profile.d/python
@@ -1,5 +1,22 @@
export PYENV_ROOT="$HOME/.pyenv"
# I have my own workon prompt, see prompt
export VIRTUAL_ENV_DISABLE_PROMPT=1

export PYENV_ROOT="$HOME/.pyenv"
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init -)"
fi

# Workaround for pyenv/poetry PATH conflicts
# see https://github.com/sdispater/poetry/issues/571

poetry() {
if [[ $@ == "shell" ]]; then
if ([[ -f "$(poetry env info -p)/bin/activate" ]] && [[ -z "${VIRTUAL_ENV:-}" ]]); then
command source $(poetry env info -p)/bin/activate
else
command poetry "$@"
fi
else
command poetry "$@"
fi
}

0 comments on commit e7889c5

Please sign in to comment.