Skip to content

Instantly share code, notes, and snippets.

@depressiveRobot
Last active June 6, 2020 13:21
Show Gist options
  • Save depressiveRobot/626e7066e77da1659c97 to your computer and use it in GitHub Desktop.
Save depressiveRobot/626e7066e77da1659c97 to your computer and use it in GitHub Desktop.
bash function to override git init/clone commands
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
}
@jan-warchol
Copy link

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

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