Skip to content

Instantly share code, notes, and snippets.

@burtlo
Created October 20, 2017 16:40
Show Gist options
  • Save burtlo/208abb70b9f98c24937e86e4b7d6603a to your computer and use it in GitHub Desktop.
Save burtlo/208abb70b9f98c24937e86e4b7d6603a to your computer and use it in GitHub Desktop.
Habitat Version Manager (hack)
#!/usr/bin/env bash
hab-get() {
local download_url="https://api.bintray.com/content/habitat/stable/darwin/x86_64/hab-%24latest-x86_64-darwin.zip?bt_package=hab-x86_64-darwin"
local tmpdir=$(mktemp -d)
pushd $tmpdir
echo "Moving to tmpdir $tmpdir"
echo "Downloading and extracting hab binary"
wget -qO- $download_url | tar xz --strip-components=1
local dest_file=$(./hab --version | tr '[:blank:]\/' '-')
echo "Installing $dest_file"
mv hab ~/habitat/bin/$dest_file
rmdir $tmpdir
popd
}
hab-ls() {
# Read the verison from the symlink
local current_version=$(readlink ~/habitat/bin/hab | sed "s/.*\/hab-//" )
# Read in all the files within the bin directory
local found_versions=( ~/habitat/bin/* )
echo
echo "Habitat Versions Available"
echo
for version in ${found_versions[@]}; do
# grab only the version numbers
local a_version=$(echo $version | sed "s/.*\/hab-//")
# This removes the symlink because it has path characters
if [[ "$a_version" = *\/* ]] ; then
continue
fi
if [ "$a_version" = "$current_version" ] ; then
echo "* $a_version"
else
echo " $a_version"
fi
done
echo
}
hab-use() {
local version=$1
ln -sf ~/habitat/bin/hab-$version ~/habitat/bin/hab
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment