Skip to content

Commit

Permalink
Easy way to activate poetry virtual env in bash
Browse files Browse the repository at this point in the history
  • Loading branch information
gnattishness committed Jun 6, 2019
1 parent c168dcf commit 939e2fe
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -12,6 +12,14 @@ and this project adheres to
Unreleased_
===========

Added
-----

* bashrc ``poetry()`` function wrapper that activates the virtual environment
instead of calling ``poetry shell``.

* As in https://github.com/sdispater/poetry/issues/571#issuecomment-496486190

0.5.0_ - 2019-06-06
===================

Expand Down
17 changes: 17 additions & 0 deletions bashrc
Expand Up @@ -109,6 +109,23 @@ if command -v direnv 1>/dev/null 2>&1; then
eval "$(direnv hook bash)"
fi

if command -v poetry 1>/dev/null 2>&1; then
# from https://github.com/sdispater/poetry/issues/571
# in poetry >1 can use $(poetry env info -p)
poetry() {
if [[ $@ == "shell" ]]; then
local VENVPATH="$(poetry debug:info | grep Path | awk '{print $3}')/bin/activate"
if ([[ -f "$VENVPATH" ]] && [[ -z "${VIRTUAL_ENV:-}" ]]); then
command source "$VENVPATH"
else
command poetry "$@"
fi
else
command poetry "$@"
fi
}
fi

export EDITOR=vim

[ -f ~/.fzf.bash ] && source ~/.fzf.bash
Expand Down

0 comments on commit 939e2fe

Please sign in to comment.