#!/bin/bash # Help show_help() { echo "usage: github []" echo "" echo "Extensions github commands are:" echo "clone Clone the repository at http://github.com//" echo "clone Clone your repository at git@github.com//" echo "commit [options] Commit on Github.com with your signed-of-by" echo "info Give informations contained in your .gitconfig" echo "page Update your webpages : git push origin 'master:gh-pages' && git pull origin 'master:gh-pages'" echo "pubkey Give your public RSA public key" echo "pull Git pull origin master" echo "push Git push origin master" echo "tiny Only for SMALL projects : git pull && git add -A && git commit -s && git push " echo "tiny Only for SMALL projects : git pull origin master && git add -A && git commit -s && git push origin master" echo "update Git pull && Git push " echo "update Git pull origin master && Git push origin master" echo "" echo "See 'git help' for more information on a git command." } # Test if no arguments have been added if [ $# -lt 1 ]; then show_help; exit 1; fi # Test the git command git > /dev/null if [ $? != 1 ]; then echo "ERROR - Git is not installed"; exit 2; fi # If you want to see all commands if [ $1 = "help" ] then #echo "The list of commands:"; show_help; exit 0; fi; # Classical command github clone if [ $1 = "clone" -a $# = 3 ]; then username=$2; repository=$3; git clone git@github.com:$username/$repository; exit 0; fi; # Other command github clone for your repository if [ $1 = "clone" -a $# = 2 ]; then username=`git config --global github.user`; repository=$2; git clone git@github.com:$username/$repository; exit 0; fi; # Classical command github commit with your signed-of-by if [ $1 = "commit" ] then git commit -s $2 $3 $4 $5 $6 $7 $8 $9; exit 0; fi; # Github update command with branch if [ $1 = "update" -a $# = 3 ] then git pull $2 $3 && git push $2 $3; exit 0; fi; # Github update command without branch if [ $1 = "update" ] then git pull origin master && git push origin master; exit 0; fi; # Github update command without branch if [ $1 = "page" -a $# = 1 ] then git pull origin 'master:gh-pages' && git push origin 'master:gh-pages'; exit 0; fi; # Github tiny command without branch if [ $1 = "tiny" -a $# = 1 ] then git pull origin master && git add -A && git commit -s && git push origin master; exit 0; fi; # Github tiny command with branch if [ $1 = "tiny" -a $# = 3 ] then git pull $2 $3 && git add -A && git commit -s && git push $2 $3; exit 0; fi; # Github wizard for the first use if [ $1 = "setup" ]; then cd ~/.ssh > /dev/null; if [ $? = 1 ]; then echo -n "You have no SSH keys"; #https://help.github.com/articles/generating-ssh-keys & https://help.github.com/articles/set-up-git echo -n "What email address did you register on Github?" read EMAIL; ssh-keygen -t rsa -C EMAIL; fi; echo -n "Now, add this SSH public key to your GitHub account:"; cat ~/.ssh/id_rsa.pub; echo -n "See: http://help.github.com/articles/generating-ssh-keys#step4" fi; # Github config for awesone use if [ $1 = "setup" ]; then echo -n "First, What's your name?"; read NAME; git config --global user.name NAME; echo -n "Now, What's your email?"; read EMAIL; git config --global user.email EMAIL; echo -n "Do you wish to configure your API account? [y/n]:" while read -r -n 1 -s answer; do if [[ $answer = [YyNn] ]]; then [[ $answer = [Yy] ]] && retval=0 [[ $answer = [Nn] ]] && retval=1 break fi if retval; then echo -n "[1/2] What's your username?"; read USERNAME; git config --global github.user USERNAME; echo -n "[2/2] What's your token?"; read TOKEN; git config --global github.token TOKEN; fi; done echo -n "Do you wish to cache your credentials, to avoid typing your password everytime? [y/n]:" while read -r -n 1 -s answer; do if [[ $answer = [YyNn] ]]; then [[ $answer = [Yy] ]] && retval=0 [[ $answer = [Nn] ]] && retval=1 break fi if retval; then git config --global credential.helper cache; echo -n "What's the cache timeout? (in seconds)"; read TIMEOUT; git config --global credential.helper 'cache --timeout=3600'; fi; done echo -n "Do you wish to configure your favorite editor? [y/n]:" while read -r -n 1 -s answer; do if [[ $answer = [YyNn] ]]; then [[ $answer = [Yy] ]] && retval=0 [[ $answer = [Nn] ]] && retval=1 break fi if retval; then echo "What is your favorite editor?" read EDITOR; git config --global core.edit EDITOR; fi; done fi; # Github info command if [ $1 = "info" ]; then username=`git config --global github.user`; email=`git config --global user.email`; editor=`git config --global core.editor`; name=`git config --global user.name`; token=`git config --global github.token`; cache=`git config --global credential.helper`; pubkey=`cat ~/.ssh/id_rsa.pub`; echo "Github account :" $username; echo "Github email :" $email; echo "Your editor :" $editor; echo "Your name :" $name; echo "Your cache :" $cache; echo "Your API token :" $token; echo "Your public key : \`github pubkey\`" ; exit 0; fi; # Github ssh command if [ $1 = "pubkey" ]; then cat ~/.ssh/id_rsa.pub; exit 0; fi; # TODO Github add remote command # Github pull command if [ $1 = "pull" -a $# = 1 ]; then git pull origin master; exit 0; fi; # Github push command if [ $1 = "push" -a $# = 1 ]; then git push origin master; exit 0; fi; # Classical command git git $*; exit 0;