Created
October 24, 2012 18:50
-
-
Save benclark/3948044 to your computer and use it in GitHub Desktop.
Bash function to go to a specified git repo in $HOME/Sites
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
# Go to a specified git repo in $HOME/Sites | |
repo() { | |
local reponame=$1 | |
local jumpto_type=$2 | |
local jumpto_which=$3 | |
local basedir="$HOME/Sites/$reponame" | |
local cd_to | |
if [ -z $reponame ]; then | |
echo "usage: repo reponame [type [which]]" | |
return | |
fi | |
if [ -d "$basedir/repo/docroot" ]; then | |
cd_to="$basedir/repo/docroot" | |
elif [ -d "$basedir/repo" ]; then | |
cd_to="$basedir/repo" | |
elif [ -d "$basedir/trunk" ]; then | |
cd_to="$basedir/trunk" | |
elif [ -d "$basedir" ]; then | |
cd_to="$basedir" | |
else | |
echo "Invalid repo." | |
return | |
fi | |
if [ ! -z $jumpto_type ]; then | |
if [ -d "$cd_to/sites/all/$jumpto_type" ]; then | |
if [ ! -z $jumpto_which ]; then | |
if [ -d "$cd_to/sites/all/$jumpto_type/$jumpto_which" ]; then | |
cd "$cd_to/sites/all/$jumpto_type/$jumpto_which" | |
else | |
echo "Invalid which." | |
return | |
fi | |
else | |
cd "$cd_to/sites/all/$jumpto_type" | |
fi | |
else | |
echo "Invalid type." | |
return | |
fi | |
else | |
cd "$cd_to" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Put this in your
~/.profile
and typerepo reponame [type [which]]
. Example usage:repo benclark.com modules features
. You would be redirected to~/Sites/benclark.com/repo/sites/all/modules/features
.