Permalink
Browse files

Adding my own git module.

  • Loading branch information...
jonathan committed Apr 15, 2012
1 parent 2449bda commit 91d4b1e7b5d25b419af275cff40bac9fa787fc0b
View
0 README
No changes.
View
@@ -0,0 +1,154 @@
+#
+# Defines Git aliases.
+#
+# Authors:
+# Sorin Ionescu <sorin.ionescu@gmail.com>
+#
+
+# Git
+alias g='git'
+
+# Branch (b)
+alias gb='git branch'
+alias gbc='git checkout -b'
+alias gbl='git branch -v'
+alias gbL='git branch -av'
+alias gbx='git branch -d'
+alias gbX='git branch -D'
+alias gbm='git branch -m'
+alias gbM='git branch -M'
+alias gbs='git show-branch'
+alias gbS='git show-branch -a'
+
+# Commit (c)
+alias gc='git commit'
+alias gca='git commit --all'
+alias gcm='git commit --message'
+alias gco='git checkout'
+alias gcO='git checkout HEAD --'
+alias gcf='git commit --amend --reuse-message HEAD'
+alias gcp='git cherry-pick --ff'
+alias gcP='git cherry-pick --no-commit'
+alias gcr='git revert'
+alias gcR='git reset "HEAD^"'
+alias gcs='git show'
+alias gcv='git fsck | awk '\''/dangling commit/ {print $3}'\'' | git show --format="SHA1: %C(green)%h%C(reset) %f" --stdin | awk '\''/SHA1/ {sub("SHA1: ", ""); print}'\'''
+
+# Data (d)
+alias gd='git ls-files'
+alias gdc='git ls-files --cached'
+alias gdx='git ls-files --deleted'
+alias gdm='git ls-files --modified'
+alias gdu='git ls-files --other --exclude-standard'
+alias gdk='git ls-files --killed'
+alias gdi='git status --porcelain --short --ignored | sed -n "s/^!! //p"'
+
+# Fetch (f)
+alias gf='git fetch'
+alias gfc='git clone'
+#alias gfm='git pull'
+alias gl='git pull'
+alias gfr='git pull --rebase'
+
+# Index (i)
+alias gia='git add'
+alias giA='git add --patch'
+alias giu='git add --update'
+alias gid='git diff --no-ext-diff --cached'
+alias giD='git diff --no-ext-diff --cached --word-diff'
+alias gir='git reset'
+alias giR='git reset --keep'
+alias gix='git rm -r --cached'
+alias giX='git rm -rf --cached'
+alias gig='git grep --cached'
+
+# Konflict (k)
+alias gkl='git status | sed -n "s/^.*both [a-z]*ed: *//p"'
+alias gka='git add $(gkl)'
+alias gke='git mergetool $(gkl)'
+alias gko='git checkout --ours --'
+alias gkO='gko $(gkl)'
+alias gkt='git checkout --theirs --'
+alias gkT='gkt $(gkl)'
+
+# Log (l)
+git_log_format_medium='--pretty=format:%C(bold)Commit:%C(reset) %C(green)%H%C(red)%d%n%C(bold)Author:%C(reset) %C(cyan)%an <%ae>%n%C(bold)Date:%C(reset) %C(blue)%ai (%ar)%C(reset)%n%+B'
+git_log_format_oneline='--pretty=format:%C(green)%h%C(reset) %s%n'
+git_log_format_brief='--pretty=format:%C(green)%h%C(reset) %s%n%C(blue)(%ar by %an)%C(red)%d%C(reset)%n'
+
+#alias gl='git log --topo-order ${git_log_format_medium}'
+alias gls='git log --topo-order --stat ${git_log_format_medium}'
+alias gld='git log --topo-order --stat --patch --full-diff ${git_log_format_medium}'
+alias glo='git log --topo-order ${git_log_format_oneline}'
+alias glg='git log --topo-order --all --graph ${git_log_format_oneline}'
+alias glb='git log --topo-order ${git_log_format_brief}'
+alias glc='git shortlog --summary --numbered'
+
+# Merge (m)
+alias gm='git merge'
+alias gmC='git merge --no-commit'
+alias gmF='git merge --no-ff'
+alias gma='git merge --abort'
+alias gmt='git mergetool'
+
+# Push (p)
+alias gp='git push'
+alias gpf='git push --force'
+alias gpa='git push --all'
+alias gpA='git push --all && git push --tags'
+alias gpt='git push --tags'
+alias gpc='git push --set-upstream origin "$(git-current-branch)"'
+alias gpp='git pull origin "$(git-current-branch)" && git push origin "$(git-branch)"'
+
+# Rebase (r)
+alias gr='git rebase'
+alias gra='git rebase --abort'
+alias grc='git rebase --continue'
+alias gri='git rebase --interactive'
+alias grs='git rebase --skip'
+
+# Remote (R)
+alias gR='git remote'
+alias gRl='git remote --verbose'
+alias gRa='git remote add'
+alias gRx='git remote rm'
+alias gRm='git remote rename'
+alias gRu='git remote update'
+alias gRc='git remote prune'
+alias gRs='git remote show'
+alias gRb='git-hub'
+
+# Stash (s)
+alias gs='git stash'
+alias gsa='git stash apply'
+alias gsc='git stash clear'
+alias gsx='git stash drop'
+alias gsl='git stash list'
+alias gsL='git stash show --patch --stat'
+alias gsp='git stash pop'
+alias gss='git stash save --include-untracked'
+alias gsS='git stash save --patch --no-keep-index'
+
+# Submodule (S)
+alias gS='git submodule'
+alias gSa='git submodule add'
+alias gSf='git submodule foreach'
+alias gSi='git submodule init'
+alias gSl='git submodule status'
+alias gSs='git submodule sync'
+alias gSu='git submodule update'
+alias gSU='git submodule update --init --recursive'
+
+# Working Copy (w)
+alias gws='git status --short'
+alias gwS='git status'
+alias gwd='git diff --no-ext-diff'
+alias gwD='git diff --no-ext-diff --word-diff'
+alias gwr='git reset --soft'
+alias gwR='git reset --hard'
+alias gwc='git clean -n'
+alias gwC='git clean -f'
+alias gwx='git rm -r'
+alias gwX='git rm -rf'
+alias gwg='git grep'
+
@@ -0,0 +1,44 @@
+#compdef git-hub
+#autoload
+
+#
+# Completes git-hub.
+#
+# Authors:
+# Sorin Ionescu <sorin.ionescu@gmail.com>
+#
+
+local state remotes remote branches files ret=1
+
+_arguments -C -s -S \
+ '1::args:->remote' \
+ '2::args:->branch' \
+ '3::args:->file' && ret=0
+
+case "$state" in
+ (remote)
+ remotes=($(
+ git config -l \
+ | grep 'remote\.[^.]*\.url' \
+ | cut -d'.' -f2))
+ _describe -t branch 'remotes' remotes && ret=0
+ ;;
+ (branch)
+ remote="$words[(($CURRENT - 1))]"
+ branches=($(
+ git branch -r \
+ | grep "${remote}/" \
+ | sed \
+ -e "/${remote}\/HEAD -> ${remote}/d" \
+ -e "s/^[[:space:]]*${remote}\///g"
+ ))
+ _describe -t branch 'branches' branches && ret=0
+ ;;
+ (file)
+ files=(${(0)"$(_call_program files git ls-files -z --exclude-standard 2>/dev/null)"})
+ _wanted file expl 'file' _multi_parts - / files && ret=0
+ ;;
+esac
+
+return $ret
+
@@ -0,0 +1,12 @@
+#compdef git-hub-short-url
+#autoload
+
+#
+# Completes git-hub-short-url.
+#
+# Authors:
+# Sorin Ionescu <sorin.ionescu@gmail.com>
+#
+
+_arguments '1:url:' && return 0
+
@@ -0,0 +1,15 @@
+#compdef git-info
+#autoload
+
+#
+# Completes git-info.
+#
+# Authors:
+# Sorin Ionescu <sorin.ionescu@gmail.com>
+#
+
+_arguments "1:toggle:((
+ on\:'enable in-prompt information for the current repository'
+ off\:'disable in-prompt information for the current repository'
+))" && return 0
+
@@ -0,0 +1,15 @@
+#
+# Displays the current Git branch.
+#
+# Authors:
+# Sorin Ionescu <sorin.ionescu@gmail.com>
+#
+
+local ref="$(git symbolic-ref HEAD 2> /dev/null)"
+if [[ -n "$ref" ]]; then
+ print "${ref#refs/heads/}"
+ return 0
+else
+ return 1
+fi
+
@@ -0,0 +1,45 @@
+#
+# Opens a GitHub repository in the default browser.
+#
+# Authors:
+# Sorin Ionescu <sorin.ionescu@gmail.com>
+#
+
+local remote branches branch current_branch file url
+
+remote="${1:-origin}"
+url=$(
+ git config -l \
+ | grep "remote.${remote}.url" \
+ | sed -En "s/remote.${remote}.url=(git|https?)(@|:\/\/)github.com(:|\/)(.+)\/(.+).git/https:\/\/github.com\/\4\/\5/p"
+)
+branches=($(
+ git branch -r | sed -e "/${remote}\/HEAD -> ${remote}/d" -e "s/^[[:space:]]*${remote}\///g"
+))
+current_branch="$(git-current-branch)"
+branch="${2:-master}"
+file="$3"
+
+if [[ -z "$2" ]]; then
+ if (( $branches[(I)$current_branch] != 0 )); then
+ branch="$current_branch"
+ else
+ branch='master'
+ fi
+fi
+
+if [[ -n "$url" ]]; then
+ url="${url}/tree/${branch}/${file}"
+
+ if (( $+commands[$BROWSER] )); then
+ "$BROWSER" "$url"
+ return 0
+ else
+ print "$0: browser not set or set to a non-existent browser" >&2
+ return 1
+ fi
+else
+ print "$0: not a Git repository or remote origin not set" >&2
+ return 1
+fi
+
@@ -0,0 +1,23 @@
+#
+# Shortens GitHub URLs.
+#
+# Authors:
+# Sorin Ionescu <sorin.ionescu@gmail.com>
+#
+
+local url="$1"
+
+if [[ "$url" == '-' ]]; then
+ read url <&0
+fi
+
+if [[ -z "$url" ]]; then
+ print "usage: $0 [ url | - ]" >&2
+fi
+
+if (( $+commands[curl] )); then
+ curl -s -i 'http://git.io' -F "url=$url" | grep 'Location:' | sed 's/Location: //'
+else
+ print "$0: command not found: curl" >&2
+fi
+
Oops, something went wrong.

0 comments on commit 91d4b1e

Please sign in to comment.