Skip to content

Commit 0892d18

Browse files
hanslovskydesyncr
authored andcommitted
Add conda support on virtualenv plugin (geometry-zsh#166)
1 parent e8fe840 commit 0892d18

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

plugins/virtualenv/README.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# Virtualenv
22

3-
You can display the current `virtualenv` by enabling this plugin.
3+
You can display the current `virtualenv` or `conda` environment by enabling this plugin. Individual colors can be assigned to each of the two environments. If both are active at the same time they will be separated by `GEOMETRY_VIRTUALENV_CONDA_SEPARATOR`.
4+
5+
6+
## Settings
7+
Set these variables to change the appearance (with default values):
8+
```bash
9+
GEOMETRY_COLOR_VIRTUALENV=green # Color for virtualenv environment name
10+
GEOMETRY_COLOR_CONDA=green # Color for conda environment name
11+
GEOMETRY_VIRTUALENV_CONDA_SEPARATOR=: # String that separates virtualenv and conda environment names if both are active
12+
```
413

514
Change the displayed color by setting the `GEOMETRY_COLOR_PROMPT` environment
615
variable. Defaults to `green`.

plugins/virtualenv/plugin.zsh

+29-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,40 @@
11
# Color definitions
2-
GEOMETRY_COLOR_VIRTUALENV=${GEOMETRY_COLOR_PROMPT:-green}
2+
DEFAULT_COLOR=${GEOMETRY_COLOR_PROMPT:-green}
3+
GEOMETRY_COLOR_VIRTUALENV=${GEOMETRY_COLOR_VIRTUALENV:-$DEFAULT_COLOR}
4+
GEOMETRY_COLOR_CONDA=${GEOMETRY_COLOR_CONDA:-$DEFAULT_COLOR}
5+
GEOMETRY_VIRTUALENV_CONDA_SEPARATOR=${GEOMETRY_VIRTUALENV_CONDA_SEPARATOR:-:}
6+
37

48
geometry_prompt_virtualenv_setup() {}
59

610
geometry_prompt_virtualenv_check() {
7-
test $VIRTUAL_ENV || return 1
11+
[ -n "${VIRTUAL_ENV}" -o -n "${CONDA_PREFIX}" ]
812
}
913

1014
geometry_prompt_virtualenv_render() {
11-
local ref=$(basename $VIRTUAL_ENV)
12-
echo "$(prompt_geometry_colorize $GEOMETRY_COLOR_VIRTUALENV "(${ref})")"
15+
16+
local environment_str=""
17+
18+
# Add virtualenv name if active
19+
if [ -n "${VIRTUAL_ENV}" ]; then
20+
local virtualenv_ref=$(basename $VIRTUAL_ENV)
21+
environment_str="$(prompt_geometry_colorize $GEOMETRY_COLOR_VIRTUALENV ${virtualenv_ref})"
22+
fi
23+
24+
# Add separator if both active
25+
if [ -n "${VIRTUAL_ENV}" -a -n "${CONDA_PREFIX}" ]; then
26+
environment_str="${environment_str}${GEOMETRY_VIRTUALENV_CONDA_SEPARATOR}"
27+
fi
28+
29+
# Add conda environment name if active
30+
if [ -n "${CONDA_PREFIX}" ]; then
31+
local conda_ref="$(basename $CONDA_PREFIX)"
32+
environment_str="${environment_str}$(prompt_geometry_colorize $GEOMETRY_COLOR_CONDA ${conda_ref})"
33+
fi
34+
35+
# Print to stdout
36+
echo "${environment_str}"
37+
1338
}
1439

1540
# Self-register plugin

0 commit comments

Comments
 (0)