themes/agnoster: Prompt broken when using pyenv (#176) (#177)

* Make sure that the output of `python --version` is always captured.
* Refactor logic to extract Python version using `awk` instead of a
  for-loop.

Fixes #176
This commit is contained in:
Jay Vercellone
2020-09-27 08:08:13 -07:00
committed by GitHub
parent c37486a76e
commit c308e0821e

View File

@@ -208,11 +208,13 @@ prompt_end() {
### virtualenv prompt
prompt_virtualenv() {
if [[ -n $VIRTUAL_ENV ]]; then
# the last word in --version command correspond to version number
for e in $($VIRTUAL_ENV/bin/python --version)
do
VENV_VERSION=$e
done
# Python could output the version information in both stdout and
# stderr (e.g. if using pyenv, the output goes to stderr).
VERSION_OUTPUT=$($VIRTUAL_ENV/bin/python --version 2>&1)
# The last word of the output of `python --version`
# corresponds to the version number.
VENV_VERSION=$(echo $VERSION_OUTPUT | awk '{print $NF}')
color=cyan
prompt_segment $color $PRIMARY_FG