Skip to content

Instantly share code, notes, and snippets.

@peterjaap
Last active December 26, 2015 03:08
Show Gist options
  • Save peterjaap/7083400 to your computer and use it in GitHub Desktop.
Save peterjaap/7083400 to your computer and use it in GitHub Desktop.
See which branch you are on immediately after entering a directory with a Git repository. Add this piece of code to your ~/.bash_profile file to run 'git branch' every time you enter a directory with a Git repository. You can comment out line 5 if you do not want to show the Magento version that is being used, if found.
function runOnFolderEntry() {
if [ "$PWD" != "$MYOLDPWD" ]; then
MYOLDPWD="$PWD";
showGitBranch ${MYOLDPWD};
showMagentoVersion ${MYOLDPWD};
fi
}
function showGitBranch() {
if [ -d "$1/.git" ]; then
git branch
fi
}
function showMagentoVersion() {
if [ -f "$1/app/Mage.php" ]; then
php -r "include '$1/app/Mage.php'; echo 'Magento version ' . Mage::getVersion(); echo \"\n\";"
fi
}
export PROMPT_COMMAND=runOnFolderEntry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment