1
0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2026-02-13 05:59:46 +08:00

Compare commits

..

2 Commits

Author SHA1 Message Date
Carlo Sala
8c5f64cc2f
feat(nvm): add corepack to lazy_cmd 2024-05-07 21:30:52 +02:00
Michael Gonzo
22bbc233e9
feat(python): autovenv keeps activated on subdirs (#12396)
Co-authored-by: Carlo Sala <carlosalag@protonmail.com>
2024-05-07 21:30:23 +02:00
4 changed files with 23 additions and 13 deletions

View File

@ -26,9 +26,9 @@ These settings should go in your zshrc file, before Oh My Zsh is sourced:
#### Lazy startup #### Lazy startup
This option will help you to defer nvm's load until you use it to speed-up your zsh startup. This will source This option will help you to defer nvm's load until you use it to speed-up your zsh startup. This will source
nvm script only when using it, and will create a function for `node`, `npm`, `npx`, `pnpm`, `yarn`, and the nvm script only when using it, and will create a function for `node`, `npm`, `npx`, `pnpm`, `yarn`, `corepack`
command(s) specified by `lazy-cmd` option, so when you call either of them, nvm will be loaded and run with and the command(s) specified by `lazy-cmd` option, so when you call either of them, nvm will be loaded and run
default version. To enable it, you can add this snippet to your zshrc, before Oh My Zsh is sourced: with default version. To enable it, you can add this snippet to your zshrc, before Oh My Zsh is sourced:
```zsh ```zsh
zstyle ':omz:plugins:nvm' lazy yes zstyle ':omz:plugins:nvm' lazy yes

View File

@ -72,9 +72,9 @@ function _omz_setup_autoload {
} }
if zstyle -t ':omz:plugins:nvm' lazy; then if zstyle -t ':omz:plugins:nvm' lazy; then
# Call nvm when first using nvm, node, npm, pnpm, yarn or other commands in lazy-cmd # Call nvm when first using nvm, node, npm, pnpm, yarn, corepack or other commands in lazy-cmd
zstyle -a ':omz:plugins:nvm' lazy-cmd nvm_lazy_cmd zstyle -a ':omz:plugins:nvm' lazy-cmd nvm_lazy_cmd
nvm_lazy_cmd=(nvm node npm npx pnpm yarn $nvm_lazy_cmd) # default values nvm_lazy_cmd=(nvm node npm npx pnpm yarn corepack $nvm_lazy_cmd) # default values
eval " eval "
function $nvm_lazy_cmd { function $nvm_lazy_cmd {
for func in $nvm_lazy_cmd; do for func in $nvm_lazy_cmd; do

View File

@ -32,8 +32,9 @@ virtual environments:
`venv`) in the current directory. `venv`) in the current directory.
- `auto_vrun`: Automatically activate the venv virtual environment when entering a directory containing - `auto_vrun`: Automatically activate the venv virtual environment when entering a directory containing
`<venv-name>/bin/activate`, and automatically deactivate it when navigating out of it (including `<venv-name>/bin/activate`, and automatically deactivate it when navigating out of it (keeps venv activated
subdirectories!). in subdirectories).
- To enable the feature, set `export PYTHON_AUTO_VRUN=true` before sourcing oh-my-zsh. - To enable the feature, set `export PYTHON_AUTO_VRUN=true` before sourcing oh-my-zsh.
- The default virtual environment name is `venv`. To use a different name, set - Plugin activates first virtual environment in lexicographic order whose name begins with `<venv-name>`.
The default virtual environment name is `venv`. To use a different name, set
`export PYTHON_VENV_NAME=<venv-name>`. For example: `export PYTHON_VENV_NAME=".venv"` `export PYTHON_VENV_NAME=<venv-name>`. For example: `export PYTHON_VENV_NAME=".venv"`

View File

@ -86,11 +86,20 @@ function mkv() {
if [[ "$PYTHON_AUTO_VRUN" == "true" ]]; then if [[ "$PYTHON_AUTO_VRUN" == "true" ]]; then
# Automatically activate venv when changing dir # Automatically activate venv when changing dir
auto_vrun() { function auto_vrun() {
if [[ -f "${PYTHON_VENV_NAME}/bin/activate" ]]; then # deactivate if we're on a different dir than VIRTUAL_ENV states
source "${PYTHON_VENV_NAME}/bin/activate" > /dev/null 2>&1 # we don't deactivate subdirectories!
else if (( $+functions[deactivate] )) && [[ $PWD != ${VIRTUAL_ENV:h}* ]]; then
(( $+functions[deactivate] )) && deactivate > /dev/null 2>&1 deactivate > /dev/null 2>&1
fi
if [[ $PWD != ${VIRTUAL_ENV:h} ]]; then
for _file in "${PYTHON_VENV_NAME}"*/bin/activate(N.); do
# make sure we're not in a venv already
(( $+functions[deactivate] )) && deactivate > /dev/null 2>&1
source $_file > /dev/null 2>&1
break
done
fi fi
} }
add-zsh-hook chpwd auto_vrun add-zsh-hook chpwd auto_vrun