Created
February 25, 2012 08:51
-
-
Save curtisharvey/1907399 to your computer and use it in GitHub Desktop.
node_versions bash function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node_versions () | |
{ | |
local ver_re='v[0-9]+\.[0-9]+\.[0-9]+'; | |
local active="$(node --version 2> /dev/null)"; | |
local installed=($(nvm ls | grep -vE ':|->' | grep -oE "$ver_re" | sort -u)); | |
local aliased=($(nvm alias | sed 's/ -> /:/')); | |
local latest="$(curl -s http://nodejs.org/dist/latest/ -o - | grep -oE "$ver_re" | sort -u)"; | |
local output=""; | |
curl -s http://nodejs.org/dist/ -o - | grep -oE "$ver_re" | sort -uV | while read v; do | |
output="$v"; | |
for i in "${installed[@]}"; | |
do | |
[[ "$v" == "$i" ]] && output="$output (installed)"; | |
done; | |
[[ "$v" == "$active" ]] && output="$output (active)"; | |
[[ "$v" == "$latest" ]] && output="$output (latest)"; | |
for i in "${aliased[@]}"; | |
do | |
[[ "$v" == "${i##*:}" ]] && output="$output (alias=${i%%:*})"; | |
done; | |
echo $output; | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment