Created
October 20, 2017 16:40
Habitat Version Manager (hack)
This file contains 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
#!/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