[shellcheck] clean up `install.sh`
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Jordan Harband · committed by Jordan Harband · parent 2228323 · Browse files · 1 file·+26 added−24 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+26 added−24 removed
- other:+26 added−24 removed
Provenance
- Commit
681c81a- Tree
91087c8- Author
Jordan Harband <ljharb@gmail.com>- Committer
Jordan Harband <ljharb@gmail.com>- Parent
2228323
1 file changed+26 added−24 removed
modified:install.sh+26 added-24 removed
5 unmodified lines6 type "$1" > /dev/null 2>&17 }8 9 nvm_install_dir() {10- echo ${NVM_DIR:-"$HOME/.nvm"}10+ echo "${NVM_DIR:-"$HOME/.nvm"}"11 }12 13 nvm_latest_version() {14 echo "v0.31.4"33 unmodified lines48 }49 50 nvm_download() {51 if nvm_has "curl"; then52- curl -q $*52+ curl -q "$@"53 elif nvm_has "wget"; then54 # Emulate curl with wget55 ARGS=$(echo "$*" | command sed -e 's/--progress-bar /--progress=bar /' \56 -e 's/-L //' \57 -e 's/-I /--server-response /' \58 -e 's/-s /-q /' \59 -e 's/-o /-O /' \60 -e 's/-C - /-c /')61+ # shellcheck disable=SC208661- wget $ARGS62+ eval wget $ARGS63 fi64 }65 66 install_nvm_from_git() {1 unmodified line68 INSTALL_DIR="$(nvm_install_dir)"69 70 if [ -d "$INSTALL_DIR/.git" ]; then71 echo "=> nvm is already installed in $INSTALL_DIR, trying to update using git"71- printf "\r=> "72+ command printf "\r=> "73 command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" fetch 2> /dev/null || {74 echo >&2 "Failed to update nvm, run 'git fetch' in $INSTALL_DIR yourself."75 exit 176 }77 else78 # Cloning to $INSTALL_DIR79 echo "=> Downloading nvm from git to '$INSTALL_DIR'"79- printf "\r=> "80+ command printf "\r=> "81 mkdir -p "$INSTALL_DIR"82 command git clone "$(nvm_source)" "$INSTALL_DIR" || {83 echo >&2 "Failed to clone nvm repo. Please report this!"84 exit 169 unmodified lines154 # The echo'ed path is guaranteed to be an existing file155 # Otherwise, an empty string is returned156 #157 nvm_detect_profile() {157- if [ -n "$PROFILE" -a -f "$PROFILE" ]; then158- echo "$PROFILE"158+ if [ -n "${PROFILE}" ] && [ -f "${PROFILE}" ]; then159+ echo "${PROFILE}"160 return161 fi162 163 local DETECTED_PROFILE42 unmodified lines206 207 local NPM_GLOBAL_MODULES208 NPM_GLOBAL_MODULES="$(209 npm list -g --depth=0 |209- sed '/ npm@/d' |210- sed '/ (empty)$/d'210+ command sed '/ npm@/d' |211+ command sed '/ (empty)$/d'212 )"213 214 local MODULE_COUNT215 MODULE_COUNT="$(215- printf %s\\n "$NPM_GLOBAL_MODULES" |216- sed -ne '1!p' | # Remove the first line216+ command printf %s\\n "$NPM_GLOBAL_MODULES" |217+ command sed -ne '1!p' | # Remove the first line218 wc -l | tr -d ' ' # Count entries219 )"220 220- if [ $MODULE_COUNT -ne 0 ]; then221+ if [ "${MODULE_COUNT}" != '0' ]; then222 cat <<-'END_MESSAGE'223 => You currently have modules installed globally with `npm`. These will no224 => longer be linked to the active version of Node when you install a new node225 => with `nvm`; and they may (depending on how you construct your `$PATH`)226 => override the binaries of modules installed with `nvm`:227 228 END_MESSAGE228- printf %s\\n "$NPM_GLOBAL_MODULES"229+ command printf %s\\n "$NPM_GLOBAL_MODULES"230 cat <<-'END_MESSAGE'231 232 => If you wish to uninstall them at a later point (or re-install them under your233 => `nvm` Nodes), you can remove them from the system Node as follows:32 unmodified lines266 267 echo268 269 local NVM_PROFILE269- NVM_PROFILE=$(nvm_detect_profile)270+ NVM_PROFILE="$(nvm_detect_profile)"271 local INSTALL_DIR272 INSTALL_DIR="$(nvm_install_dir)"273 274 SOURCE_STR="\nexport NVM_DIR=\"$INSTALL_DIR\"\n[ -s \"\$NVM_DIR/nvm.sh\" ] && . \"\$NVM_DIR/nvm.sh\" # This loads nvm\n"275 275- if [ -z "$NVM_PROFILE" ] ; then276- echo "=> Profile not found. Tried $NVM_PROFILE (as defined in \$PROFILE), ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile."276+ if [ -z "${NVM_PROFILE-}" ] ; then277+ echo "=> Profile not found. Tried ${NVM_PROFILE} (as defined in \$PROFILE), ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile."278 echo "=> Create one of them and run this script again"278- echo "=> Create it (touch $NVM_PROFILE) and run this script again"279+ echo "=> Create it (touch ${NVM_PROFILE}) and run this script again"280 echo " OR"281 echo "=> Append the following lines to the correct file yourself:"281- printf "$SOURCE_STR"282+ command printf "${SOURCE_STR}"283 else283- if ! command grep -qc '/nvm.sh' "$NVM_PROFILE"; then284- echo "=> Appending source string to $NVM_PROFILE"285- printf "$SOURCE_STR" >> "$NVM_PROFILE"284+ if ! command grep -qc '/nvm.sh' "${NVM_PROFILE}"; then285+ echo "=> Appending source string to ${NVM_PROFILE}"286+ command printf "%s" "${SOURCE_STR}" >> "${NVM_PROFILE}"287 else287- echo "=> Source string already in $NVM_PROFILE"288+ echo "=> Source string already in ${NVM_PROFILE}"289 fi290 fi291 292 # Source nvm292- . "$INSTALL_DIR/nvm.sh"293+ # shellcheck source=/dev/null294+ . "${INSTALL_DIR}/nvm.sh"295 296 nvm_check_global_modules297 298 nvm_install_node299 300 nvm_reset301 302 echo "=> Close and reopen your terminal to start using nvm or run the following to use it now:"301- printf "$SOURCE_STR"303+ command printf "%s" "${SOURCE_STR}"304 }305 306 #307 # Unsets the various functions defined12 unmodified lines