Skip to content

Instantly share code, notes, and snippets.

@austinjreilly
Last active August 29, 2015 13:56
Show Gist options
  • Save austinjreilly/8827859 to your computer and use it in GitHub Desktop.
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.
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