Last active
June 6, 2020 13:21
-
-
Save depressiveRobot/626e7066e77da1659c97 to your computer and use it in GitHub Desktop.
bash function to override git init/clone commands
This file contains 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 | |
/usr/local/bin/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
Note that you don't have to enter the repo to set the email - with new enough versions of Git, you can pass configuration options at clone-time. This means you won't have to bother with getting the directory.
See how I solve the email problem here: https://github.com/jan-warchol/dotfiles/blob/devel/bin/git-cln