Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Zsh compatibility #157

Closed
wants to merge 2 commits into from

4 participants

@koenpunt

Fixed compatibility with zsh
Added method to normalize versions so they are comparable and method to 'format' a version number (prepend v if not starting with number).

@beilharz
[[ -r $NVM_DIR/bash_completion ]] && . $NVM_DIR/bash_completion 

still does not work with zsh.

bashcompinit 

should do the trick.

taken from git_complete.bash:

if [[ -n ${ZSH_VERSION-} ]]; then
    autoload -U +X bashcompinit && bashcompinit
fi
@vvo

I do not understand I use zsh and nvm already, what are you fixing?

@beilharz

Do you also use completion like in https://github.com/creationix/nvm#bash-completion?
For me that only works with bashcompinit.

@ljharb
Collaborator

I'm going to close this - @koenpunt, if you're interested in reopening this, please freshly rebase on master, and ensure it works in zsh, bash, and sh. It would also be helpful if you described in more detail the purpose of this PR.

@ljharb ljharb closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 21, 2012
  1. @koenpunt
  2. @koenpunt

    Some more compatibility with zsh

    koenpunt authored
    Prepend a v for version numbers if its not already there
This page is out of date. Refresh to see the latest.
Showing with 31 additions and 16 deletions.
  1. +31 −16 nvm.sh
View
47 nvm.sh
@@ -36,8 +36,10 @@ nvm_version()
# The default version is the current one
if [ ! "$PATTERN" ]; then
PATTERN='current'
+ else
+ PATTERN=`nvm_format_version $PATTERN`
fi
-
+
VERSION=`nvm_ls $PATTERN | tail -n1`
echo "$VERSION"
@@ -57,6 +59,27 @@ nvm_remote_version()
fi
}
+nvm_normalize_version()
+{
+ echo "$1" | sed -e 's/^v//' | awk -F. '{ printf("%d%03d%03d\n", $1,$2,$3); }';
+}
+
+nvm_format_version()
+{
+ echo "$1" | sed -e 's/^\([0-9]\)/v\1/g'
+}
+
+nvm_binary_available()
+{
+ # binaries started with node 0.8.6
+ MINIMAL="0.8.6"
+ VERSION=$1
+ if [ $(nvm_normalize_version $VERSION) -ge $(nvm_normalize_version $MINIMAL) ]; then
+ echo "1"
+ fi
+ return
+}
+
nvm_ls()
{
PATTERN=$1
@@ -71,7 +94,7 @@ nvm_ls()
return
fi
# If it looks like an explicit version, don't do anything funny
- if [[ "$PATTERN" == v?*.?*.?* ]]; then
+ if echo "$PATTERN" | grep 'v.*\..*\..*' ; then
VERSIONS="$PATTERN"
else
VERSIONS=`(cd $NVM_DIR; \ls -d v${PATTERN}* 2>/dev/null) | sort -t. -k 1.2,1n -k 2,2n -k 3,3n`
@@ -88,9 +111,7 @@ nvm_ls_remote()
{
PATTERN=$1
if [ "$PATTERN" ]; then
- if echo "${PATTERN}" | grep -v '^v' ; then
- PATTERN=v$PATTERN
- fi
+ PATTERN=`nvm_format_version "$PATTERN"`
else
PATTERN=".*"
fi
@@ -175,14 +196,7 @@ nvm()
# shortcut - try the binary if possible.
if [ -n "$os" ]; then
- binavail=
- # binaries started with node 0.8.6
- case "$VERSION" in
- v0.8.[012345]) binavail=0 ;;
- v0.[1234567]) binavail=0 ;;
- *) binavail=1 ;;
- esac
- if [ $binavail -eq 1 ]; then
+ if [[ `nvm_binary_available "$VERSION"` -eq 1 ]]; then
t="$VERSION-$os-$arch"
url="http://nodejs.org/dist/$VERSION/node-${t}.tar.gz"
if (
@@ -245,11 +259,12 @@ nvm()
;;
"uninstall" )
[ $# -ne 2 ] && nvm help && return
- if [[ $2 == `nvm_version` ]]; then
- echo "nvm: Cannot uninstall currently-active node version, $2."
+ PATTERN=`nvm_format_version $2`
+ if [[ $PATTERN == `nvm_version` ]]; then
+ echo "nvm: Cannot uninstall currently-active node version, $PATTERN."
return
fi
- VERSION=`nvm_version $2`
+ VERSION=`nvm_version $PATTERN`
if [ ! -d $NVM_DIR/$VERSION ]; then
echo "$VERSION version is not installed yet... installing"
nvm install $VERSION
Something went wrong with that request. Please try again.