Skip to content

Instantly share code, notes, and snippets.

@curtisharvey
Created February 25, 2012 08:51
Show Gist options
  • Save curtisharvey/1907399 to your computer and use it in GitHub Desktop.
Save curtisharvey/1907399 to your computer and use it in GitHub Desktop.
node_versions bash function
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