Created
February 5, 2025 02:44
-
-
Save shellscape/dfdbc2944241e157caf9e29a16bbb5c6 to your computer and use it in GitHub Desktop.
Add local node_modules/.bin to the PATH dynamically
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 characters
function add_node_modules_bin() { | |
export _OLD_NODE_PATH="$PATH" | |
if [[ -d "./node_modules/.bin" ]]; then | |
export PATH="$PWD/node_modules/.bin:$PATH" | |
fi | |
} | |
function remove_node_modules_bin() { | |
if [[ -n "$_OLD_NODE_PATH" ]]; then | |
export PATH="$_OLD_NODE_PATH" | |
unset _OLD_NODE_PATH | |
fi | |
} | |
# Hook into directory changes | |
add-zsh-hook chpwd add_node_modules_bin | |
# Hook that runs when shell starts (new tab/window) | |
precmd_functions+=(add_node_modules_bin) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment