Last active
August 29, 2015 13:56
-
-
Save austinjreilly/8827859 to your computer and use it in GitHub Desktop.
Shell function that allows users of the University of Texas Web Central to quickly toggle between test and live environments.
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
function switchenv(){ | |
TEST="/export/httpd/vhosts/wwwtest/data/law" | |
PROD="/export/bulk/law" | |
CURRENTDIR=$(pwd -P) | |
if [[ "$CURRENTDIR" == *"$TEST"* ]] | |
then | |
#In test, so remove test prefix and replace with prod prefix | |
NEWDIR=${CURRENTDIR/$TEST/$PROD} | |
#Does NEWDIR exist? | |
if [ -d "$NEWDIR" ] | |
then | |
cd $NEWDIR | |
echo "Now you're in Prod."; | |
else | |
echo "Directory does not exist in Prod environment. You're still in Test."; | |
fi | |
elif [[ "$CURRENTDIR" == *"$PROD"* ]] | |
then | |
#In prod, so remove prod prefix and replace with test prefix | |
NEWDIR=${CURRENTDIR/$PROD/$TEST} | |
#Does NEWDIR exist? | |
if [ -d "$NEWDIR" ] | |
then | |
cd $NEWDIR | |
echo "Now you're in Test."; | |
else | |
echo "Directory does not exist in Test environment. You're still in Prod."; | |
fi | |
else | |
echo "If you see this, then something went wrong. Apology. Apologies all around."; | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment