Skip to content

Instantly share code, notes, and snippets.

@trueheart78
Last active January 26, 2021 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trueheart78/2ffabced0e0cdc91144b12b528de378f to your computer and use it in GitHub Desktop.
Save trueheart78/2ffabced0e0cdc91144b12b528de378f to your computer and use it in GitHub Desktop.
Git Init Prompt
# remap git to point to g()
git () {
g "$@"
}
# git super command
# make sure with zsh that the git plugin is not used
# as it will override this command
g () {
if [[ $# -gt 0 ]]
then
if [[ `uname` = 'Darwin' && $1 = "init" ]]; then
command git "$@"
# prompt for the username and email to use
while true; do
echo -n "Will this be a ⚠️ work-related ⚠️ repo? (y/n) "
read yn
case $yn in
[Yy]* ) git_work; break;;
[Nn]* ) git_personal; break;;
* ) echo "Please answer yes or no.";;
esac
done
elif [[ $1 = "push" ]]; then
branch=`command git rev-parse --abbrev-ref HEAD`
if [[ $branch = 'main' ]]
then
while true; do
echo -n "Push to 🔥 Main 🔥 ? (y/n) "
read yn
case $yn in
[Yy]* ) command git "$@"; break;;
[Nn]* ) echo "❤️ Push-to-Main crisis averted ❤️"; break;;
* ) echo "Please answer yes or no.";;
esac
done
elif [[ $branch = 'master' ]]
then
while true; do
echo -n "Push to 🔥 Master 🔥 ? (y/n) "
read yn
case $yn in
[Yy]* ) command git "$@"; break;;
[Nn]* ) echo "❤️ Push-to-Master crisis averted ❤️"; break;;
* ) echo "Please answer yes or no.";;
esac
done
else
command git "$@"
fi
else
command git "$@"
fi
else
command git status
fi
}
# git local repo user
git_personal () {
command git config user.name "Your Name"
command git config user.email "you@personal-domain.com"
}
# git work repo user
git_work () {
command git config user.name "Your Professional Name"
command git config user.email "you@work-domain.com"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment