Skip to content

Instantly share code, notes, and snippets.

@lalomartins
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lalomartins/e04317bd953f954bb0a1 to your computer and use it in GitHub Desktop.
Save lalomartins/e04317bd953f954bb0a1 to your computer and use it in GitHub Desktop.
#!/bin/sh
set -e
VERSION="$1"
shift
for bin in "$@"; do
binpath=$(realpath -s "${bin}")
echo "${binpath} -> ${VERSION}"
wrapperpath="${HOME}/.local/bin/$(basename "${bin}")"
if [ -e "${wrapperpath}" ]; then
echo "${wrapperpath} already exists, leaving alone!"
continue
fi
echo "create ${wrapperpath}"
cat > "${wrapperpath}" <<-EOF
#!/bin/sh
export NVM_DIR="${HOME}/.nvm"
. \${NVM_DIR}/nvm.sh
nvm use ${VERSION}
exec "${binpath}" "\$@"
EOF
chmod u+x "${wrapperpath}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment