Merge pull request #528 from creationix/remove_last_expr
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Remove last usages of `expr`
authored by Jordan Harband · committed by Jordan Harband · parents edf36a8, 7fd6d05 · Browse files · 1 file·+33 added−19 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+33 added−19 removed
- other:+33 added−19 removed
Provenance
- Commit
6bae6c0- Tree
45bbd78- Author
Jordan Harband <ljharb@gmail.com>- Committer
Jordan Harband <ljharb@gmail.com>- Parent 1
edf36a8- Parent 2
7fd6d05
1 file changed+33 added−19 removed
modified:nvm.sh+33 added-19 removed
110 unmodified lines111 RHS=$(nvm_normalize_version "$2")112 [ $LHS -gt $RHS ];113 }114 115+nvm_version_greater_than_or_equal_to() {116+ local LHS117+ LHS=$(nvm_normalize_version "$1")118+ local RHS119+ RHS=$(nvm_normalize_version "$2")120+ [ $LHS -ge $RHS ];121+}122+123 nvm_version_dir() {124 local NVM_USE_NEW_DIR125 NVM_USE_NEW_DIR="$1"126 if [ -z "$NVM_USE_NEW_DIR" ] || [ "$NVM_USE_NEW_DIR" = "new" ]; then89 unmodified lines216 }217 218 nvm_binary_available() {219 # binaries started with node 0.8.6212- local LAST_VERSION_WITHOUT_BINARY213- LAST_VERSION_WITHOUT_BINARY="0.8.5"214- nvm_version_greater "$1" "$LAST_VERSION_WITHOUT_BINARY"220+ local FIRST_VERSION_WITH_BINARY221+ FIRST_VERSION_WITH_BINARY="0.8.6"222+ nvm_version_greater_than_or_equal_to "$1" "$FIRST_VERSION_WITH_BINARY"223 }224 225 nvm_ls_current() {226 local NODE_PATH331 unmodified lines558 then559 nvm use $VERSION560 if ! nvm_has "npm" ; then561 echo "Installing npm..."554- if [ "`expr "$VERSION" : '\(^v0\.1\.\)'`" != '' ]; then562+ if nvm_version_greater 0.2.0 "$VERSION"; then563 echo "npm requires node v0.2.3 or higher" >&2556- elif [ "`expr "$VERSION" : '\(^v0\.2\.\)'`" != '' ]; then557- if [ "`expr "$VERSION" : '\(^v0\.2\.[0-2]$\)'`" != '' ]; then564+ elif nvm_version_greater_than_or_equal_to "$VERSION" 0.2.0; then565+ if nvm_version_greater 0.2.3 "$VERSION"; then566 echo "npm requires node v0.2.3 or higher" >&2567 else568 nvm_download https://npmjs.org/install.sh -o - | clean=yes npm_install=0.2.19 sh569 fi36 unmodified lines606 done607 608 ;;609 "deactivate" )602- if [ `expr "$PATH" : ".*$NVM_DIR/.*/bin.*"` != 0 ] ; then603- export PATH=`nvm_strip_path "$PATH" "/bin"`610+ local NEWPATH611+ NEWPATH="$(nvm_strip_path "$PATH" "/bin")"612+ if [ "$PATH" = "$NEWPATH" ]; then613+ echo "Could not find $NVM_DIR/*/bin in \$PATH" >&2614+ else615+ export PATH="$NEWPATH"616 hash -r617 echo "$NVM_DIR/*/bin removed from \$PATH"606- else607- echo "Could not find $NVM_DIR/*/bin in \$PATH" >&2618 fi609- if [ `expr "$MANPATH" : ".*$NVM_DIR/.*/share/man.*"` != 0 ] ; then610- export MANPATH=`nvm_strip_path "$MANPATH" "/share/man"`611- echo "$NVM_DIR/*/share/man removed from \$MANPATH"612- else619+620+ NEWPATH="$(nvm_strip_path "$MANPATH" "/share/man")"621+ if [ "$MANPATH" = "$NEWPATH" ]; then622 echo "Could not find $NVM_DIR/*/share/man in \$MANPATH" >&2614- fi615- if [ `expr "$NODE_PATH" : ".*$NVM_DIR/.*/lib/node_modules.*"` != 0 ] ; then616- export NODE_PATH=`nvm_strip_path "$NODE_PATH" "/lib/node_modules"`617- echo "$NVM_DIR/*/lib/node_modules removed from \$NODE_PATH"623 else624+ export MANPATH="$NEWPATH"625+ echo "$NVM_DIR/*/share/man removed from \$MANPATH"626+ fi627+628+ NEWPATH="$(nvm_strip_path "$NODE_PATH" "/lib/node_modules")"629+ if [ "$NODE_PATH" = "$NEWPATH" ]; then630 echo "Could not find $NVM_DIR/*/lib/node_modules in \$NODE_PATH" >&2631+ else632+ export NODE_PATH="$NEWPATH"633+ echo "$NVM_DIR/*/lib/node_modules removed from \$NODE_PATH"634 fi635 ;;636 "use" )637 if [ $# -eq 0 ]; then224 unmodified lines862 "--version" )863 echo "0.16.1"864 ;;865 "unload" )852- unset -f nvm nvm_print_versions nvm_checksum nvm_ls_remote nvm_ls nvm_remote_version nvm_version nvm_rc_version nvm_version_greater > /dev/null 2>&1866+ unset -f nvm nvm_print_versions nvm_checksum nvm_ls_remote nvm_ls nvm_remote_version nvm_version nvm_rc_version nvm_version_greater nvm_version_greater_than_or_equal_to > /dev/null 2>&1867 unset RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_DIR NVM_CD_FLAGS > /dev/null 2>&1868 ;;869 * )870 nvm help10 unmodified lines