-
-
Save crcastle/3088510 to your computer and use it in GitHub Desktop.
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
githubAccount() { # Syntax: githubAccount <file> | |
# Check for Github account name | |
if [[ "$githubAccount" == '' ]]; then | |
if [[ ! -f "$file" ]]; then | |
# If .github doesn't exist then ask for the name and save it | |
echo -n "What is your Github name? " | |
read githubAccount | |
touch "$file" | |
echo "$githubAccount" > "$file" | |
else | |
# If .github does exist get the name from it | |
while read name; do | |
githubAccount="$name" | |
done < "$file" | |
fi | |
fi | |
} | |
github() { # Syntax: github [username] [repo] | |
# Note: OS X uses `open` instead of `xdg-open` and not sure if OS X has | |
# - nohup(Forks to background process and doesn't interfere with current shell) | |
githubAccount ~/.github_account | |
if [[ "$2" != '' ]]; then | |
# If the username and repo was given | |
nohup xdg-open http://github.com/"$1"/"$2" > /dev/null 2>&1 & | |
elif [[ "$1" != '' ]]; then | |
# If only the username was given | |
# Note: Maybe change this so it opens a repo in the users github page | |
nohup xdg-open http://github.com/"$1" > /dev/null 2>&1 & | |
elif [[ "$@" == '' ]]; then | |
# No arguments given, open users github | |
nohup xdg-open http://github.com/"$githubAccount" > /dev/null 2>&1 & | |
fi | |
} | |
alias ghub="github" | |
ginit() { # Syntax: ginint [dir] | |
githubAccount ~/.github_account | |
if [[ "$@" != '' ]]; then | |
dir="$@" | |
else | |
dir="${PWD##*/}" | |
fi | |
git init | |
git remote add origin git@github.com:"$githubAccount"/"$dir".git | |
echo "Created .git directory and created origin remote for $dir..." | |
} | |
gstat() { git status "$@" } # Syntax: gstat [git args] | |
gdiff() { git diff "$@" --color-words } # Syntax: gdiff [git args] | |
gpull() { git pull "$@" } # Syntax: gpull [git args] | |
gcommit() { git commit "$@" } # Syntax: gcommit [git args] | |
gadd() { # Syntax: gadd [git args] [files] | |
git add "$@" | |
} | |
alias gstage="gadd" | |
gclone() { # Syntax: gclone [user] <repo> | |
if [[ "$2" == "" ]]; then | |
# Assume it's the users github repo | |
githubAccount ~/.github_account | |
if [[ ! -d "$1" ]]; then | |
git clone git@github.com:"$githubAccount"/"$1".git | |
cd "$1" | |
git remote add origin git@github.com:"$githubAccount"/"$1".git | |
echo "Successfully cloned $1, and added an origin remote for it..." | |
else | |
echo "A Clone already exists for this repo..." | |
exit 1 | |
fi | |
else | |
if [[ ! -d "$2" ]]; then | |
git clone git@github.com:"$1"/"$2".git | |
cd "$2" | |
echo "Successfully cloned $2 from $1..." | |
else | |
echo "A Clone already exists for this repo..." | |
exit 1 | |
fi | |
fi | |
} | |
gpush() { # Syntax: gpush [remote] <branch> | |
if [[ "$2" == "" ]]; then | |
# Assume we're pushing to origin | |
git push origin "$1" | |
else | |
git push "$1" "$2" | |
fi | |
} | |
gcompush() { # Syntax: gcompush [remote] <branch> <message> | |
if [[ "$3" == "" ]]; then | |
# Assume we're pushing to origin | |
gcommit -m "$2" | |
gpush "$1" | |
else | |
gcommit -m "$3" | |
gpush "$1" "$2" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment