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

Use $CONDA_PROMPT_MODIFIER if it exists #1389

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ The segments that are currently available are:
##### anaconda

This segment shows your active anaconda environment. It relies on either the
`CONDA_ENV_PATH` or the `CONDA_PREFIX` (depending on the `conda` version)
environment variable to be set which happens when you properly `source
activate` an environment.
`CONDA_PROMPT_MODIFIER`, `CONDA_ENV_PATH`, or `CONDA_PREFIX` (depending on the
`conda` version) environment variable to be set which happens when you properly
`source activate` an environment.

Special configuration variables:

Expand Down
24 changes: 16 additions & 8 deletions powerlevel9k.zsh-theme
Original file line number Diff line number Diff line change
Expand Up @@ -299,14 +299,22 @@ right_prompt_segment() {
################################################################
# Anaconda Environment
prompt_anaconda() {
# Depending on the conda version, either might be set. This
# variant works even if both are set.
local _path=$CONDA_ENV_PATH$CONDA_PREFIX
if ! [ -z "$_path" ]; then
# config - can be overwritten in users' zshrc file.
set_default POWERLEVEL9K_ANACONDA_LEFT_DELIMITER "("
set_default POWERLEVEL9K_ANACONDA_RIGHT_DELIMITER ")"
"$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "$POWERLEVEL9K_ANACONDA_LEFT_DELIMITER$(basename $_path)$POWERLEVEL9K_ANACONDA_RIGHT_DELIMITER" 'PYTHON_ICON'
local modifier
if [ -n "$CONDA_PROMPT_MODIFIER" ]; then
modifier="$CONDA_PROMPT_MODIFIER"
else
# Depending on the conda version, either might be set. This
# variant works even if both are set.
local _path=$CONDA_ENV_PATH$CONDA_PREFIX
if ! [ -z "$_path" ]; then
# config - can be overwritten in users' zshrc file.
set_default POWERLEVEL9K_ANACONDA_LEFT_DELIMITER "("
set_default POWERLEVEL9K_ANACONDA_RIGHT_DELIMITER ")"
modifier="$POWERLEVEL9K_ANACONDA_LEFT_DELIMITER$(basename $_path)$POWERLEVEL9K_ANACONDA_RIGHT_DELIMITER"
fi
fi
if [ -n "$modifier" ]; then
"$1_prompt_segment" "$0" "$2" "blue" "$DEFAULT_COLOR" "$modifier" 'PYTHON_ICON'
fi
}

Expand Down
15 changes: 15 additions & 0 deletions test/segments/anaconda.spec
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,19 @@ function testAnacondaSegmentWorks() {
assertEquals "%K{004} %F{000}icon-here %F{000}(tmptest) %k%F{004}%f " "$(build_left_prompt)"
}

function testAnacondaSegmentWorksIfCondaPromptModifierIsSet() {
local -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(anaconda)
local POWERLEVEL9K_PYTHON_ICON="icon-here"

# Load Powerlevel9k
source powerlevel9k.zsh-theme

local CONDA_PROMPT_MODIFIER="(modifier)"
local CONDA_ENV_PATH=/tmp
local CONDA_PREFIX="test"

assertEquals "%K{004} %F{000}icon-here %F{000}(modifier) %k%F{004}%f " "$(build_left_prompt)"
}

source shunit2/shunit2