Skip to content

Instantly share code, notes, and snippets.

@rynr
Last active March 14, 2016 14:48
Show Gist options
  • Save rynr/df326d0c665e8abbb052 to your computer and use it in GitHub Desktop.
Save rynr/df326d0c665e8abbb052 to your computer and use it in GitHub Desktop.
Java Environment by project
#!/bin/sh
#
# To enable this, add the following line to your ´.bashrc`:
# export PROMPT_COMMAND="source $HOME/bin/prompt_command"
#
# The variable `PROMPT_COMMAND` is used to execute some bash code
# before any prompt.
# If you need different environments for different projects and have
# your projects grouped with a main directory like the following:
#
# ~/workspace/clientA/projectA1
# ~/workspace/clientA/projectA2
# ~/workspace/clientA/projectA..
# ~/workspace/clientB/projectB1
# ~/workspace/clientB/projectB2
# ~/workspace/clientB/projectB..
#
# This script will identify the client-part of the URL and check for
# different files if they exist and link them to the default-path.
# For example if you change in the directory `~/workspace/clientA`
# and there is a directory `~/.git-clientA`, it will link `~/.git` to
# this directory. If there's no specific directory it will link the
# directory `~/.git-default`.
# You can also setup some environments by adding a `setenv.sh`-script
# to the clients directory (like `~/workspace/clientA/setenv.sh`).
PROJECT_DIR=$HOME/workspace
PROJECT=`pwd | sed -e "s#${PROJECT_DIR}##" | cut -d '/' -f 2`
if [ -n "$PROJECT" ]; then
if [ -z "$PREV_PROJECT" ] || [ "$PREV_PROJECT" != "$PROJECT" ]; then
PREV_PROJECT="$PROJECT"
if [ -d "$HOME/.git-$PROJECT" ]; then
echo "configure git to $PROJECT"
ln -snf "$HOME/.git-$PROJECT" "$HOME/.git"
else
echo "configure git to default"
ln -snf "$HOME/.git-default" "$HOME/.git"
fi
if [ -d "$HOME/.m2/settings-$PROJECT.xml" ]; then
echo "configure maven to $PROJECT"
ln -snf "$HOME/.m2/settings-$PROJECT.xml" "$HOME/.m2/settings.xml"
else
echo "configure maven to default"
ln -snf "$HOME/.m2/settings-default.xml" "$HOME/.m2/settings.xml"
fi
if [ -x "$HOME/Projects/$PROJECT/setenv.sh" ]; then
echo "set env for $PROJECT"
source "$HOME/Projects/$PROJECT/setenv.sh"
fi
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment