Last active
January 26, 2021 15:44
-
-
Save trueheart78/2ffabced0e0cdc91144b12b528de378f to your computer and use it in GitHub Desktop.
Git Init Prompt
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
# 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 "[email protected]" | |
} | |
# git work repo user | |
git_work () { | |
command git config user.name "Your Professional Name" | |
command git config user.email "[email protected]" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment