From 997d37765a1897ddd01c44f78a0ecad59235d9b9 Mon Sep 17 00:00:00 2001 From: Marley Rae Date: Thu, 25 Jan 2024 13:14:28 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Finally=20get=20Node.js=20instal?= =?UTF-8?q?ls=20working!!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- node/install.sh | 15 +++++++-------- node/nvm.zsh | 29 +---------------------------- script/utils.sh | 8 +++----- 3 files changed, 11 insertions(+), 41 deletions(-) diff --git a/node/install.sh b/node/install.sh index cae4463..081c8ac 100755 --- a/node/install.sh +++ b/node/install.sh @@ -1,14 +1,13 @@ -#!/usr/bin/env bash -# vim:set ft=bash: +#!/usr/bin/env zsh -cd "$(dirname "${BASH_SOURCE[0]}")" \ +cd "$(dirname ${(%):-%x})" \ && source "../script/utils.sh" -if ! [[ -d "~/.zsh-plugins/zsh-nvm" ]]; then - execute \ - "git clone https://github.com/lukechilds/zsh-nvm.git ~/.zsh-plugins/zsh-nvm" \ - "zsh-nvm" -fi +execute \ + "if ! [ -d \"$HOME/.zsh-plugins/zsh-nvm\" ]; then git clone https://github.com/lukechilds/zsh-nvm.git ~/.zsh-plugins/zsh-nvm; fi" \ + "zsh-nvm" + +source "./nvm.zsh" execute "nvm install lts/iron" "Node.js 20.x" diff --git a/node/nvm.zsh b/node/nvm.zsh index cc187b4..d5338fb 100644 --- a/node/nvm.zsh +++ b/node/nvm.zsh @@ -1,32 +1,5 @@ #!/usr/bin/env zsh export NVM_COMPLETION=true +export NVM_AUTO_USE=true source ~/.zsh-plugins/zsh-nvm/zsh-nvm.plugin.zsh - -# Call nvm use automatically whenever a directory containing .nvmrc is entered. -autoload -U add-zsh-hook - -function load-nvmrc() -{ - local nvmrc_path - nvmrc_path="$(nvm_find_nvmrc)" - - if [[ -n "$nvmrc_path" ]]; then - local nvmrc_node_version - nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")") - - if [[ "$nvmrc_node_version" == "N/A" ]]; then - nvm install - elif [[ "$nvmrc_node_version" != "$(nvm version)" ]]; then - nvm use - fi - - elif [[ -n "$(PWD=$OLDPWD nvm_find_nvmrc)" ]] \ - && [[ "$(nvm version)" != "$(nvm version default)" ]]; then - echo "Reverting to nvm default version" - nvm use default - fi -} - -add-zsh-hook chpwd load-nvmrc -load-nvmrc diff --git a/script/utils.sh b/script/utils.sh index 62319e7..0a36e6f 100755 --- a/script/utils.sh +++ b/script/utils.sh @@ -38,11 +38,9 @@ ask_for_sudo() print_in_color() { - string=$(echo "$1" | tr -s " ") - printf "%b" \ "$(tput setaf "$2" 2> /dev/null)" \ - "$string" \ + "$1" \ "$(tput sgr0 2> /dev/null)" } @@ -164,7 +162,7 @@ show_spinner() tput sc while kill -0 "$PID" &> /dev/null; do - frame_text=" [${FRAMES:i++%NUMBER_OF_FRAMES:1}] $MSG" + frame_text=" [${FRAMES:$((i++%NUMBER_OF_FRAMES)):1}] $MSG" # Print frame text. printf "%s" "$frame_text" @@ -193,7 +191,7 @@ is_git_repository() set_trap() { trap -p "$1" | grep "$2" &> /dev/null \ - || trap '$2' "$1" + || trap "$2" "$1" } kill_all_subproccesses()