Add `nvm_get_latest`

master
Jordan Harband 2014-12-21 16:33:52 -08:00
parent c0a20f2fa3
commit 0a739e3fa9
1 changed files with 18 additions and 0 deletions

18
nvm.sh
View File

@ -12,6 +12,24 @@ nvm_has() {
type "$1" > /dev/null 2>&1 type "$1" > /dev/null 2>&1
} }
nvm_get_latest() {
local NVM_LATEST_URL
if nvm_has "curl"; then
NVM_LATEST_URL="$(curl -w "%{url_effective}\n" -L -s -S http://latest.nvm.sh -o /dev/null)"
elif nvm_has "wget"; then
NVM_LATEST_URL="$(wget http://latest.nvm.sh --server-response -O /dev/null 2>&1 | awk '/^ Location: /{DEST=$2} END{ print DEST }')"
else
>&2 echo 'nvm needs curl or wget to proceed.'
return 1
fi
if [ "_$NVM_LATEST_URL" = "_" ]; then
>&2 echo "http://latest.nvm.sh did not redirect to the latest release on Github"
return 2
else
echo "$NVM_LATEST_URL" | awk -F'/' '{print $NF}'
fi
}
nvm_download() { nvm_download() {
if nvm_has "curl"; then if nvm_has "curl"; then
curl $* curl $*