Skip to content

Instantly share code, notes, and snippets.

@ateucher
Forked from depressiveRobot/git-function.sh
Last active September 19, 2017 17:53
Show Gist options
  • Save ateucher/4d463dfb90171957c071ee2f67484390 to your computer and use it in GitHub Desktop.
Save ateucher/4d463dfb90171957c071ee2f67484390 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
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
}
@ateucher
Copy link
Author

You also need to save the git-email-prompt.sh in ~/bin and make it executable with:

cd ~/bin
chmod +x git-email-prompt.sh

And finally, to make this function available, save git-function.sh in ~/bin and put this line in your .bashrc:

# Source the git override function that prompts for email
. ~/bin/git-function.sh

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