Last active
June 21, 2016 15:18
-
-
Save pv8/100dc28985ee522b47df3d00eaa41d9f to your computer and use it in GitHub Desktop.
Handy script to setup git local config for several git projects
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
#!/usr/bin/env bash | |
set -e | |
prompt_user() { | |
read -p "$1 [hit <enter> to abort]: " user_input | |
if [[ -z "$user_input" ]]; then | |
echo "Aborting git local config setup." | |
exit 1 | |
fi | |
echo $user_input | |
} | |
CODE_DIR=$(prompt_user "Type the the root dir (full path) of your projects (Example: $HOME/workspace/)?") | |
GIT_USER_NAME=$(prompt_user "Type your full name") | |
GIT_USER_EMAIL=$(prompt_user "Type your email") | |
CURR_DIR=$(pwd) | |
cd $CODE_DIR | |
for entry in $(ls -lrt -d -1 $PWD/*/); do | |
if [[ -d $entry/.git/ ]]; then | |
cd $entry | |
echo "Setting git config for $(pwd)" | |
git config --local user.name "$GIT_USER_NAME" | |
git config --local user.email $GIT_USER_EMAIL | |
fi | |
done | |
cd $CURR_DIR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To run the script:
$ bash -c "$(curl -fSL https://gist.githubusercontent.com/pv8/100dc28985ee522b47df3d00eaa41d9f/raw)"