Welcome back to another edition of TWIL, our weekly series where we serve up bite-sized pieces of wisdom to spice up your tech know-how. This week, join Emily as she introduces a nifty Shell script to Automatically Run nvm use
, a smart way to ensure the right Node version with a helpful nvm use
command embedded in directory changesโa true lifesaver for those seeking command line efficiency. Stay tuned as Emily demonstrates the ease of integrating this tweak into your workflow. With her tips, managing Node environments becomes as simple as hopping into a directory, perfect for the forgetful among us keen on keeping our Shell game strong.
Automatically Run nvm use Shell Function
Recently I've found myself forgetting to run nvm use
, so I decided to add it to my usual cl
function.
Here's the basic version:
# A function used as a more advanced version of `cd`
# - Changes into the specified directory
# - If an .nvmrc file exists, active it using `nvm use`
function cl () {
cd "$@"
if test -f ".nvmrc"; then
echo "๐๐๐ .nvmrc found - activating Node environment\n"
nvm use
fi
}
And my full cl
command:
# A function used as a more advanced version of `cd`
# - Changes into the specified directory
# - Clears the screen
# - If an .nvmrc file exists, active it using `nvm use`
# - Lists the current directory
function cl () {
cd "$@" && clear
if test -f ".nvmrc"; then
echo "๐๐๐ .nvmrc found - activating Node environment\n"
nvm use
fi
ls -laAhF
}
- Shell
- Bash
- Helpers
- Node.js