Last active
August 29, 2015 14:03
-
-
Save woledzki/e2dc77a810f2053acf1f to your computer and use it in GitHub Desktop.
Installs some useful aliases
This file contains 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
#!/bin/bash | |
usage() { | |
msg=$1 | |
if [[ $msg ]]; then | |
logMsg "$msg" | |
fi | |
echo "gitconfig-client -t dev-webapps1 | |
-t <team name> team name, which should be the same as | |
-h Displays this message | |
" | |
exit 1; | |
} | |
installAliases() { | |
teamName=$1 | |
logMsg "Installing simple aliases" | |
logMsg "'git s' for 'git status'" | |
git config --global alias.s "status" | |
logMsg "'git a' for 'git add'" | |
git config --global alias.a "add" | |
logMsg "'git c' for 'git commit'" | |
git config --global alias.c "commit" | |
logMsg "'git p' for 'git push'" | |
git config --global alias.p "push" | |
logMsg "'git o' for 'git checkout'" | |
git config --global alias.o "checkout" | |
logMsg "'git b' for 'git branch'" | |
git config --global alias.b "branch" | |
logMsg "Installing smart aliases" | |
logMsg "'git dev' for 'git checkout dev-${teamName}'" | |
git config --global alias.dev "!f() { git checkout dev-${teamName} ; }; f" | |
logMsg "'git rc' for 'git checkout release-candidate'" | |
git config --global alias.rc "!f() { git checkout release-candidate ; }; f" | |
logMsg "'git bc' for remote branch creation 'git bc origin/master tkt-123'" | |
git config --global alias.bc "!f() { git push origin \$1:refs/heads/\$2 ; git fetch origin ; git checkout --track -b \$2 origin/\$2 ; }; f" | |
logMsg "'git m some-branch' for 'git fetch origin; git merge --no-ff --no-commit origin/some-branch'" | |
git config --global alias.m "!f() { git fetch origin; git merge --no-ff --no-commit remotes/origin/\$1 ; }; f" | |
logMsg "'git cl' for generating simple changelog" | |
git config --global alias.cl "!f() { d=\${1-release-candidate}; git log --no-merges --pretty='%s (%an) [%h]' origin/\$d..HEAD | grep -v '(ci)' | xargs -I {} echo ' o {}'; }; f" | |
logMsg "'git cn' for generating changelog committers names" | |
git config --global alias.cn "!f() { d=\${1-release-candidate}; git log --no-merges --pretty='%an' origin/\$d..HEAD | grep -v '^ci' | sort | uniq; }; f" | |
} | |
main() { | |
teamName='' | |
# get options | |
while getopts t:h opt; do | |
case "$opt" in | |
t) | |
teamName="$OPTARG" | |
;; | |
h) | |
usage | |
;; | |
"") | |
usage "Missing arguments"; | |
;; | |
*) | |
usage "Unrecognied option '$opt'"; | |
;; | |
esac | |
done; | |
if [[ -z $teamName ]]; then | |
usage "You have to specify team name (-t)" | |
fi | |
installAliases "$teamName" | |
exit 0 | |
} | |
logMsg() { | |
msg=$1 | |
echo " ${msg}" | |
} | |
logError() { | |
msg=$1 | |
exitCode=$2 | |
echo " ${msg}" | |
exit $exitCode | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment