Last active
June 16, 2023 09:36
-
-
Save larsyencken/6961c509c7bbc738dbc792977f0e31a7 to your computer and use it in GitHub Desktop.
Nushell: detect Python and Node environments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# just a partial config, only look at env_change | |
{ | |
hooks: { | |
env_change: { | |
PWD: [ | |
{ | |
# if you enter a python project | |
condition: {|before, after| ["pyproject.toml" "requirements.txt"] | any {|f| $f | path exists } } | |
# drop any prior virtualenv, then use a new one if it exists | |
code: " | |
if ('.venv/bin/python' | path exists) { | |
let-env PATH = ($env.PATH | split row (char esep) | filter {|p| not $p =~ '.venv' } | prepend $\"($env.PWD)/.venv/bin\") | |
} else { | |
let-env PATH = ($env.PATH | split row (char esep) | filter {|p| not $p =~ '.venv' }) | |
} | |
" | |
}, | |
{ | |
# if you enter a node project with nvm | |
condition: {|before, after| ".nvmrc" | path exists } | |
# drop any prior nvm context, and use a node version from fnm if one exists | |
code: "( | |
if ($\"($env.HOME)/.fnm/node-versions/v(cat .nvmrc)/installation/bin\" | path exists) { | |
let-env PATH = ($env.PATH | split row (char esep) | filter {|p| not p =~ '.fnm'} | prepend $\"($env.HOME)/.fnm/node-versions/v(cat .nvmrc)/installation/bin\") | |
} else { | |
print $\"Node v(cat .nvmrc) is not installed\"; | |
print $\"Please run: fnm install (cat .nvmrc)\" | |
let-env PATH = ($env.PATH | split row (char esep) | filter {|p| not p =~ '.fnm'}) | |
} | |
)" | |
} | |
] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment