-
Notifications
You must be signed in to change notification settings - Fork 1
/
nodejs
executable file
·48 lines (37 loc) · 1.36 KB
/
nodejs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env bash
if ! command -v mise > /dev/null; then
echo "mise is required to run this script"
exit 1
fi
mise install node@18 node@20
# Default version
mise use -g node@20
# Activate node corepack
mise exec node@18 -- corepack enable
mise exec node@20 -- corepack enable
# Sometimes after running corepack enable the shims are not updated
mise reshim
# Shell completions
mise exec node@20 -- npm completion > ~/.local/share/bash-completion/completions/npm
# NOTE: this is a snippet from `npm completion` output but works fine even with `bashcompinit` in .zshrc
cat > ~/.local/share/zsh-completion/_npm <<'EOL'
#compdef npm
_npm() {
local si=$IFS
compadd -- $(COMP_CWORD=$((CURRENT-1)) \
COMP_LINE=$BUFFER \
COMP_POINT=0 \
npm completion -- "${words[@]}" \
2>/dev/null)
IFS=$si
}
if [ "$funcstack[1]" = "_npm" ]; then
_npm "$@"
else
compdef _npm npm
fi
EOL
curl -o ~/.local/share/bash-completion/completions/yarn https://raw.githubusercontent.com/dsifford/yarn-completion/master/yarn-completion.bash
curl -o ~/.local/share/zsh-completion/_yarn https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/plugins/yarn/_yarn
mise exec node@20 -- pnpm completion bash > ~/.local/share/bash-completion/completions/pnpm
mise exec node@20 -- pnpm completion zsh > ~/.local/share/zsh-completion/_pnpm