Skip to content

Commit

Permalink
Add _lp_python_env() and _lp_python_env_color()
Browse files Browse the repository at this point in the history
I can't find any explaination why the environments were trunkated to the
last '/'. I could use some people not wanting a long string in their
prompt, but I'm sure others want the whole original string.
  • Loading branch information
Rycieos committed Nov 25, 2020
1 parent 78dee3c commit 03434d3
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions liquidprompt
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,26 @@ _lp_http_proxy_color() {
lp_http_proxy_color="${LP_COLOR_PROXY}${LP_MARK_PROXY}${NO_COL}"
}

_lp_python_env() {
(( LP_ENABLE_VIRTUALENV )) || return 2

# Why are these trunkated to the last '/' section? It has always been this
# way, and the original author didn't explain why.
if [[ -n "${VIRTUAL_ENV-}" ]]; then
lp_python_env="${VIRTUAL_ENV##*/}"
elif [[ -n "${CONDA_DEFAULT_ENV-}" ]]; then
lp_python_env="${CONDA_DEFAULT_ENV##*/}"
else
return 1
fi
}

_lp_python_env_color() {
_lp_python_env || return $?

lp_python_env_color="[${LP_COLOR_VIRTUALENV}${lp_python_env}${NO_COL}]"
}

# return: 0 if login user, 1 if not, 2 if root
_lp_user() {
if (( EUID == 0 )); then
Expand Down Expand Up @@ -2320,13 +2340,8 @@ _lp_theme_prompt() {
LP_PROXY=
fi

# Display the current Python virtual environment, if available
if [[ "$LP_ENABLE_VIRTUALENV,${VIRTUAL_ENV-}${CONDA_DEFAULT_ENV-}" = 1,?* ]]; then
if [[ -n "${VIRTUAL_ENV-}" ]]; then
LP_VENV=" [${LP_COLOR_VIRTUALENV}${VIRTUAL_ENV##*/}${NO_COL}]"
else
LP_VENV=" [${LP_COLOR_VIRTUALENV}${CONDA_DEFAULT_ENV##*/}${NO_COL}]"
fi
if _lp_python_env_color; then
LP_VENV=" $lp_python_env_color"
else
LP_VENV=
fi
Expand Down

0 comments on commit 03434d3

Please sign in to comment.