Simplify and add documentation

This commit is contained in:
Marc Cornellà 2024-07-15 18:53:54 +02:00
commit b1400713fc
No known key found for this signature in database
GPG key ID: 0314585E776A9C1B
2 changed files with 34 additions and 11 deletions

View file

@ -7,12 +7,38 @@ To use it, add `conda-env` to the plugins array of your zshrc file:
plugins=(... conda-env) plugins=(... conda-env)
``` ```
The plugin creates a `conda_prompt_info` function that you can use in your The plugin creates a `conda_prompt_info` function that you can use in your theme, which displays the
theme, which displays the basename of the current `$CONDA_DEFAULT_ENV`. It uses basename of the current `$CONDA_DEFAULT_ENV`.
two variables to control how that is shown:
You can use this prompt function in your themes, by adding it to the `PROMPT` or `RPROMPT` variables. See [Example](#example) for more information.
## Settings
It uses two variables to control how the information is shown:
- `ZSH_THEME_CONDA_PREFIX`: sets the prefix of the CONDA_DEFAULT_ENV. - `ZSH_THEME_CONDA_PREFIX`: sets the prefix of the CONDA_DEFAULT_ENV.
Defaults to `[`. Defaults to `[`.
- `ZSH_THEME_CONDA_SUFFIX`: sets the suffix of the CONDA_DEFAULT_ENV. - `ZSH_THEME_CONDA_SUFFIX`: sets the suffix of the CONDA_DEFAULT_ENV.
Defaults to `]`. Defaults to `]`.
## Example
```sh
ZSH_THEME_CONDA_PREFIX='conda:%F{green}'
ZSH_THEME_CONDA_SUFFIX='%f'
RPROMPT='$(conda_prompt_info)'
```
## `CONDA_CHANGEPS1`
This plugin also automatically sets the `CONDA_CHANGEPS1` variable to `false` to avoid conda changing the prompt
automatically. This has the same effect as running `conda config --set changeps1 false`.
You can override this behavior by adding `unset CONDA_CHANGEPS1` in your `.zshrc` file, after Oh My Zsh has been
sourced.
References:
- https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#determining-your-current-environment
- https://conda.io/projects/conda/en/latest/user-guide/configuration/use-condarc.html#precedence

View file

@ -1,12 +1,9 @@
function conda_prompt_info(){ function conda_prompt_info(){
if command -v pyenv &>/dev/null && [[ $plugins == *"virtualenv"* ]]; then [[ -n ${CONDA_DEFAULT_ENV} ]] || return
return echo "${ZSH_THEME_CONDA_PREFIX=[}${CONDA_DEFAULT_ENV:t:gs/%/%%}${ZSH_THEME_CONDA_SUFFIX=]}"
else
[[ -n ${CONDA_DEFAULT_ENV} ]] || return
echo "${ZSH_THEME_CONDA_PREFIX=[}${CONDA_DEFAULT_ENV:t:gs/%/%%}${ZSH_THEME_CONDA_SUFFIX=]}"
fi
} }
# disables display (${CONDA_DEFAULT_ENV}) # Has the same effect as `conda config --set changeps1 false`
# - https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#determining-your-current-environment
# - https://conda.io/projects/conda/en/latest/user-guide/configuration/use-condarc.html#precedence
export CONDA_CHANGEPS1=false export CONDA_CHANGEPS1=false