Dotfiles/site-modules/core/files/oh-my-zsh/custom/nvmrc.zsh
Ade Attwood 7f95ee24f8 refactor(vim): move to eslint_d from eslint
Eslint has become slow for some projects for reasons unknown. In an
attempt to speed up my linting process, I'm experimenting with eslint_d,
which keeps a process running. For the time being, I'd like to keep
linting and formatting separate from the Language Server Protocol (LSP)
to avoid the need to install every LSP. This way, I can have `shfmt`
without the bash LSP, for example.

For JavaScript, I may consider moving this into an LSP since I use it
for work, which would justify combining responsibilities. However, for
now, I'll be giving eslint_d a try.
2023-11-08 07:56:41 +00:00

44 lines
1.5 KiB
Bash

#!/bin/zsh
#
# Custom plugin to check the .nvmrc file. When entering a directory, it checks
# to see if you have the desired node version installed for the current
# project. If it is, it will use it automatically, if not, then it will ask you
# if you want to install it. After, it will install all the JS developer tools
# for that version of NodeJS.
#
# This is a different implementation than the default oh-my-zsh version. The
# main difference is that it will not reset the node version when leaving a
# directory. It will only preform an action if there is a `.nvmrc` file in the
# current directory. It will not even use the `nvm_find_nvmrc` command because
# any interaction with nvm make the stranded `cd` command extremely sluggish.
maybe_nvm_install() {
local version="$1"
if read -q "do?Node version ${version} is not installed, would you like to install it? (Y/N) "; then
echo ""
nvm install "${version}"
echo "Installing all of the JS developer tools for this version of node with npm"
npm install -g yarn typescript-language-server typescript emmet-ls cspell vscode-langservers-extracted prettier jsdoc eslint eslint_d
fi
}
load_nvmrc() {
local nvmrc_path=".nvmrc"
if [[ -f "$nvmrc_path" ]]; then
local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")
if [[ "$nvmrc_node_version" = "N/A" ]]; then
maybe_nvm_install "$(cat "${nvmrc_path}")"
else
nvm use > /dev/null
fi
fi
}
autoload -U add-zsh-hook
add-zsh-hook chpwd load_nvmrc
load_nvmrc