Skip to content

Instantly share code, notes, and snippets.

@benclark
Created October 24, 2012 18:50
Show Gist options
  • Save benclark/3948044 to your computer and use it in GitHub Desktop.
Save benclark/3948044 to your computer and use it in GitHub Desktop.
Bash function to go to a specified git repo in $HOME/Sites
# 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
}
@benclark
Copy link
Author

Put this in your ~/.profile and type repo reponame [type [which]]. Example usage: repo benclark.com modules features. You would be redirected to ~/Sites/benclark.com/repo/sites/all/modules/features.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment