I am setting up a zsh shell environment and I wanted to try writing a simple function for my own learning purposes:
# ~/.zsh-extensions/conda_which
# get version in conda env
function conda_which {
# this comes from Flament's answer below
readonly env=${1:?"The environment must be specified."}
readonly pkg=${2:?"The package must be specified."}
conda list -n $env | grep $pkg
}
and in my .zshrc
# ~/.zshrc
# this comes from Terbeck's answer below
fpath=(~/.zsh-extensions/ $fpath)
# this comes from _conda file recommendation for conda autocompletion
fpath+=~/.zsh-extensions/conda-zsh-completion
# this comes from Terbeck's answer below
autoload -U $fpath[1]/*(.:t)
So now I can do:
$ conda_which test_env numpy
numpy 1.23.5 py310h5d7c261_0 conda-forge
instead of
$ conda list -n test_env | grep numpy
because I often forget if it is env list or list env and this is just a toy example.
The issue I am facing is that the output of conda_which losses grep's color highlighting numpy. How do I maintain this?
citations:
@Frank Terbeck's answer on how to autoload custom functions
@Damien Flament's answer on how to pass arguments to zsh functions