Last active
February 17, 2024 16:18
-
-
Save u-sho/00471a058cbf35d00fb1ed3dcedb094b to your computer and use it in GitHub Desktop.
Volta Bash Integration
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
# ref1: https://github.com/nvm-sh/nvm?tab=readme-ov-file#bash | |
# ref2: https://zenn.dev/hrbrain/articles/989acf69368896 | |
cdvolta() { | |
command cd "$@" || return $? | |
if [[ -e ".node-version" ]]; then | |
content=$(cat .node-version) | |
volta install node@$content | |
volta install npm@bundled | |
fi | |
if [[ -e ".nvmrc" ]]; then | |
content=$(cat .nvmrc) | |
case $content in | |
"lts/argon") | |
volta install node@4 | |
;; | |
"lts/boron") | |
volta install node@6 | |
;; | |
"lts/carbon") | |
volta install node@8 | |
;; | |
"lts/dubnium") | |
volta install node@10 | |
;; | |
"lts/erbium") | |
volta install node@12 | |
;; | |
"lts/fermium") | |
volta install node@14 | |
;; | |
"lts/gallium") | |
volta install node@16 | |
;; | |
"lts/hydrogen") | |
volta install node@18 | |
;; | |
"lts/iron") | |
volta install node@20 | |
;; | |
"lts/jod") | |
volta install node@22 | |
;; | |
"lts/*") | |
volta install node@lts | |
;; | |
"latest" | "current" | "node" | "*") | |
volta install node@latest | |
;; | |
*) | |
volta install node@$content | |
;; | |
esac | |
volta install npm@bundled | |
fi | |
} | |
alias cd='cdvolta' | |
cdvolta "$PWD" || exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment