-
-
Save ateucher/4d463dfb90171957c071ee2f67484390 to your computer and use it in GitHub Desktop.
bash function to override git init/clone commands
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
function git() { | |
for i do | |
lastArgument=$i # last argument can be the directory or the repository url | |
done | |
command git $@ | |
if [[ $? -eq 0 ]] # only show prompt if git command was successful | |
then | |
if [[ "$1" = "init" || "$1" = "clone" ]] | |
then | |
if [[ -d "$lastArgument" ]] | |
then | |
# it was the directory argument, cd it | |
cd $lastArgument | |
else | |
# no directory given, parse it from repository url | |
cd $(echo $lastArgument | awk -F/ '{ print $NF }' | rev | sed 's/tig.//' | rev) | |
fi | |
git-email-prompt.sh | |
fi | |
else | |
# return the exit code of the failed git command call | |
return $? | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You also need to save the
git-email-prompt.sh
in ~/bin and make it executable with:And finally, to make this function available, save
git-function.sh
in ~/bin and put this line in your .bashrc: