Skip to content

Commit

Permalink
Display .zshrc instructions in install script
Browse files Browse the repository at this point in the history
  • Loading branch information
abejfehr committed Feb 17, 2022
1 parent ca4540c commit 43b1145
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 29 deletions.
31 changes: 3 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,37 +32,12 @@ function nvm() {
For the zsh shell hook that automatically switches node versions on directory change, you can simply start by downloading the `resolve_node_version` binary to your `.nvm` folder:

```bash
curl -o- https://raw.githubusercontent.com/abejfehr/fast-nvm-switcher/v0.1.4/install.sh | bash
curl -o- https://raw.githubusercontent.com/abejfehr/fast-nvm-switcher/v0.1.5/install.sh | bash
```

And add a relatively small hook into your `.zshrc` file:
And follow the instructions given.

```bash
# Strips the path of previous nvm node directories
nvm_strip_path() {
command printf %s "${1-}" | command awk -v NVM_DIR="${NVM_DIR}" -v RS=: '
index($0, NVM_DIR) == 1 {
path = substr($0, length(NVM_DIR) + 1)
if (path ~ "^(/versions/[^/]*)?/[^/]*'"${2-}"'.*$") { next }
}
{ print }' | command paste -s -d: -
}

# Resolves node version based on nearest nvmrc and adds its directory to the PATH
load-nvmrc() {
NODE_PATH=$(${NVM_DIR}/resolve_node_version)
if [ -n "$NODE_PATH" ]; then
PATH="$PATH:$NODE_PATH"
echo "Note location set to $NODE_PATH"
fi
}

autoload -U add-zsh-hook
add-zsh-hook chpwd load-nvmrc
load-nvmrc
```

That's it, changing directories should now also be blazing fast ⚡️
Once you've complete that, changing directories should now also be blazing fast ⚡️

> **Note:** If you already use one of the "Deeper shell integrations" from the [nvm README](https://github.com/nvm-sh/nvm#deeper-shell-integration), you'll have to remove those before following these instructions.
Expand Down
33 changes: 32 additions & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,37 @@

cd $NVM_DIR

curl -L -O https://github.com/abejfehr/fast-nvm-switcher/releases/download/0.1.4/resolve_node_version
curl -L -O https://github.com/abejfehr/fast-nvm-switcher/releases/download/v0.1.5/resolve_node_version

chmod +x $NVM_DIR/resolve_node_version

echo ""
echo ""
echo "Successfully downloaded the 'resolve_node_version' utility"
echo ""
echo ""
echo "Finalize your shell integration by copying the following lines to your .zshrc:"
echo ""
echo ""
echo " nvm_strip_path() {"
echo " command printf %s "\${1-}" | command awk -v NVM_DIR="\${NVM_DIR}" -v RS=: '"
echo " index(\$0, NVM_DIR) == 1 {"
echo " path = substr(\$0, length(NVM_DIR) + 1)"
echo " if (path ~ "^\(/versions/[^/]*\)?/[^/]*'"${2-}"'.*$") { next }"
echo " }"
echo " { print }' | command paste -s -d: -"
echo " }"
echo " "
echo " load-nvmrc() {"
echo " NODE_PATH=\$(\${NVM_DIR}/resolve_node_version)"
echo " if [ -n "\$NODE_PATH" ]; then"
echo " PATH="\$PATH:\$NODE_PATH""
echo " echo "Note location set to \$NODE_PATH""
echo " fi"
echo " }"
echo " "
echo " autoload -U add-zsh-hook"
echo " add-zsh-hook chpwd load-nvmrc"
echo " load-nvmrc"
echo ""
echo ""

0 comments on commit 43b1145

Please sign in to comment.