mirror of
https://github.com/robbyrussell/oh-my-zsh.git
synced 2026-11-28 03:13:03 +01:00
feat(conda): add environment completion for cna and cnrn (#13632)
This commit is contained in:
1 parent
90e5779f1f
commit
d419792761
2 files changed
+32
-5
No files matched your search
+11
-3
@@ -1,6 +1,6 @@
|
||||
# conda plugin
|
||||
|
||||
The conda plugin provides [aliases](#aliases) for `conda`, usually installed via [anaconda](https://www.anaconda.com/) or [miniconda](https://docs.conda.io/en/latest/miniconda.html).
|
||||
The conda plugin provides [aliases](#aliases) and [completion](#completion) for `conda`, usually installed via [anaconda](https://www.anaconda.com/) or [miniconda](https://docs.conda.io/en/latest/miniconda.html).
|
||||
|
||||
To use it, add `conda` to the plugins array in your zshrc file:
|
||||
|
||||
@@ -28,10 +28,18 @@ plugins=(... conda)
|
||||
| `cnle` | `conda list --export` | Export the list of installed packages in the current environment |
|
||||
| `cnles` | `conda list --explicit > spec-file.txt` | Export the list of installed packages in the current environment to a spec file |
|
||||
| `cnr` | `conda remove` | Remove given package |
|
||||
| `cnrn` | `conda remove -y -all -n` | Remove all packages in the specified environment |
|
||||
| `cnrp` | `conda remove -y -all -p` | Remove all packages in the specified prefix |
|
||||
| `cnrn` | `conda remove -y --all -n` | Remove all packages in the specified environment |
|
||||
| `cnrp` | `conda remove -y --all -p` | Remove all packages in the specified prefix |
|
||||
| `cnry` | `conda remove -y` | Remove given package without confirmation |
|
||||
| `cnsr` | `conda search` | Search conda repositories for package |
|
||||
| `cnu` | `conda update` | Update conda package manager |
|
||||
| `cnua` | `conda update --all` | Update all installed packages |
|
||||
| `cnuc` | `conda update conda` | Update conda package manager |
|
||||
|
||||
## Completion
|
||||
|
||||
Tab completion is available for the following commands, using the environment list conda keeps in
|
||||
`~/.conda/environments.txt`:
|
||||
|
||||
- `cna`: completes environment names for `conda activate`
|
||||
- `cnrn`: completes environment names for `conda remove -y --all -n`
|
||||
@@ -1,4 +1,7 @@
|
||||
alias cna='conda activate'
|
||||
unalias cna cnrn 2>/dev/null
|
||||
cna() { conda activate "$@"; }
|
||||
cnrn() { conda remove -y --all -n "$@"; }
|
||||
|
||||
alias cnab='conda activate base'
|
||||
alias cncf='conda env create -f'
|
||||
alias cncn='conda create -y -n'
|
||||
@@ -14,10 +17,26 @@ alias cnl='conda list'
|
||||
alias cnle='conda list --export'
|
||||
alias cnles='conda list --explicit > spec-file.txt'
|
||||
alias cnr='conda remove'
|
||||
alias cnrn='conda remove -y --all -n'
|
||||
alias cnrp='conda remove -y --all -p'
|
||||
alias cnry='conda remove -y'
|
||||
alias cnsr='conda search'
|
||||
alias cnu='conda update'
|
||||
alias cnua='conda update --all'
|
||||
alias cnuc='conda update conda'
|
||||
|
||||
_omz_conda_envs() {
|
||||
emulate -L zsh -o extended_glob
|
||||
local envs_file="$HOME/.conda/environments.txt"
|
||||
[[ -r "$envs_file" ]] || return 1
|
||||
|
||||
# Each line is an env prefix; named envs live under <dir>/envs/<name>.
|
||||
# The root prefix (base) and envs created with -p have no name and are skipped.
|
||||
local -aU envs
|
||||
envs=(${(f)"$(<$envs_file)"})
|
||||
envs=(${${(M)envs:#*/envs/[^/]##}:t})
|
||||
(( ${#envs} )) && compadd -Q -a envs
|
||||
}
|
||||
|
||||
if (( $+functions[compdef] )); then
|
||||
compdef _omz_conda_envs cna cnrn
|
||||
fi
|
||||
Reference in new issue
Block a user