Created
September 11, 2019 16:59
-
-
Save haxiomic/b0ce703090ad13a51408f8c23dab5b79 to your computer and use it in GitHub Desktop.
set haxe version bash
This file contains hidden or 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
#folders should be named like: haxe-3.1.3, and the regular haxe folder should be removed | |
alias setHaxeVersion=_set_haxe_version | |
function _set_haxe_version(){ | |
HAXE_PARENT="$(dirname "$HAXE_HOME")" | |
FIND_RESULT="`find $HAXE_PARENT -maxdepth 1 -name "haxe-*$1"`" | |
NUM_RESULTS=`echo "$FIND_RESULT" | wc -l` | |
if [[ $NUM_RESULTS -eq 1 ]] && [[ -n $FIND_RESULT ]] ; then | |
if [[ ! -d $HAXE_HOME/lib ]] ; then #make haxe dir & lib if they don't exist | |
sudo mkdir -p $HAXE_HOME/lib | |
fi | |
sudo ln -sf $FIND_RESULT/haxe $HAXE_HOME || return 1 | |
sudo ln -sf $FIND_RESULT/haxelib $HAXE_HOME || return 1 | |
sudo ln -sf $FIND_RESULT/std $HAXE_HOME || return 1 | |
VERSION="`basename $FIND_RESULT`" | |
printf "${BRIGHT_GREEN}haxe version set to ${BRIGHT_WHITE}${BOLD}${VERSION//haxe-/}${RESET}\n" | |
else | |
if [[ -n $FIND_RESULT ]]; then #not empty find result | |
VERSIONS="`basename -a $FIND_RESULT`" | |
printf "${BRIGHT_WHITE}${VERSIONS//haxe-/}\n" | |
else | |
printf "${BOLD}${RED}Version $1 not found.\n${BRIGHT_WHITE}Available versions are:${RESET}\n" | |
FIND_ALL=`find $HAXE_PARENT -type d -maxdepth 1 -name "haxe-*"` | |
VERSIONS="`basename -a $FIND_ALL`" | |
printf "${BRIGHT_WHITE}${VERSIONS//haxe-/}\n" | |
fi | |
fi | |
unset FIND_RESULT | |
unset NUM_RESULTS | |
unset VERSIONS | |
unset VERSION | |
unset FIND_ALL | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment