Last active
November 2, 2018 13:39
-
-
Save tobiashm/da3aba3071c826c742bb02e2ad0d14ba to your computer and use it in GitHub Desktop.
Revisions
-
tobiashm revised this gist
Nov 2, 2018 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -5,8 +5,10 @@ # I.e. other terminal windows will have the default Node version, unless they’re also changed. use-node() { wanted=$([ "$1" == "" ] && echo "node" || echo "node@$1") prefix=$(brew --prefix $wanted 2> /dev/null) if [ "$prefix" != "" ]; then PATH="$(echo $PATH | tr ':' '\n' | grep -v ${prefix%@*} | tr '\n' ':')" if [ "$1" != "" ]; then PATH="$prefix/bin:$PATH"; fi export PATH else echo "Node version '$1' not available" -
tobiashm revised this gist
Nov 2, 2018 . 1 changed file with 5 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,18 +1,14 @@ # Assumes you have installed individual major versions with Homebrew, like node@8, # this command allows you to switch by calling e.g. `use-node 8`, or to get the # current latest version (`brew install node`) if you don't pass an argument. # Notice: Since it modifies the env, this will only work for the current session. # I.e. other terminal windows will have the default Node version, unless they’re also changed. use-node() { wanted=$([ "$1" == "" ] && echo "node" || echo "node@$1") if brew ls "$wanted" &>/dev/null; then PATH="$(brew --prefix $wanted)/bin:$(echo $PATH | tr ':' '\n' | grep -v $(brew --prefix node) | tr '\n' ':')" export PATH else echo "Node version '$1' not available" fi } -
tobiashm created this gist
Nov 2, 2018 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ # Assumes you have installed individual major versions with Homebrew, like node@8, # this command allows you to switch by calling e.g. `use-node 8`, or to get the # current latest version (`brew install node`) if you don't pass an argument. # Notice: Unlike e.g. `nvm` this will change the node version for all sessions, # since it changes the `/usr/local/bin/node` symlink. use-node() { wanted=$([ "$1" == "" ] && echo "node" || echo "node@$1") if brew ls "$wanted" &>/dev/null; then if which node &> /dev/null; then for possible in $(brew ls | grep -E "^node($|@)"); do brew unlink $possible > /dev/null done fi brew link --force --overwrite $wanted > /dev/null else echo "Node version '$1' not available" fi }