git.plugin.zsh 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. # Aliases
  2. alias g='git'
  3. compdef g=git
  4. alias gst='git status'
  5. compdef _git gst=git-status
  6. alias gd='git diff'
  7. compdef _git gd=git-diff
  8. alias gdc='git diff --cached'
  9. compdef _git gdc=git-diff
  10. alias gdt='git diff-tree --no-commit-id --name-only -r'
  11. compdef _git gdc=git diff-tree --no-commit-id --name-only -r
  12. alias gl='git pull'
  13. compdef _git gl=git-pull
  14. alias gup='git pull --rebase'
  15. compdef _git gup=git-fetch
  16. alias gp='git push'
  17. compdef _git gp=git-push
  18. alias gd='git diff'
  19. gdv() { git diff -w "$@" | view - }
  20. compdef _git gdv=git-diff
  21. alias gc='git commit -v'
  22. compdef _git gc=git-commit
  23. alias gc!='git commit -v --amend'
  24. compdef _git gc!=git-commit
  25. alias gca='git commit -v -a'
  26. compdef _git gc=git-commit
  27. alias gca!='git commit -v -a --amend'
  28. compdef _git gca!=git-commit
  29. alias gcmsg='git commit -m'
  30. compdef _git gcmsg=git-commit
  31. alias gco='git checkout'
  32. compdef _git gco=git-checkout
  33. alias gcm='git checkout master'
  34. alias gr='git remote'
  35. compdef _git gr=git-remote
  36. alias grv='git remote -v'
  37. compdef _git grv=git-remote
  38. alias grmv='git remote rename'
  39. compdef _git grmv=git-remote
  40. alias grrm='git remote remove'
  41. compdef _git grrm=git-remote
  42. alias grset='git remote set-url'
  43. compdef _git grset=git-remote
  44. alias grup='git remote update'
  45. compdef _git grset=git-remote
  46. alias grbi='git rebase -i'
  47. compdef _git grbi=git-rebase
  48. alias grbc='git rebase --continue'
  49. compdef _git grbc=git-rebase
  50. alias grba='git rebase --abort'
  51. compdef _git grba=git-rebase
  52. alias gb='git branch'
  53. compdef _git gb=git-branch
  54. alias gba='git branch -a'
  55. compdef _git gba=git-branch
  56. alias gbr='git branch --remote'
  57. alias gcount='git shortlog -sn'
  58. compdef gcount=git
  59. alias gcl='git config --list'
  60. alias gcp='git cherry-pick'
  61. compdef _git gcp=git-cherry-pick
  62. alias glg='git log --stat --max-count=10'
  63. compdef _git glg=git-log
  64. alias glgg='git log --graph --max-count=10'
  65. compdef _git glgg=git-log
  66. alias glgga='git log --graph --decorate --all'
  67. compdef _git glgga=git-log
  68. alias glo='git log --oneline --decorate --color'
  69. compdef _git glo=git-log
  70. alias glog='git log --oneline --decorate --color --graph'
  71. compdef _git glog=git-log
  72. alias gss='git status -s'
  73. compdef _git gss=git-status
  74. alias ga='git add'
  75. compdef _git ga=git-add
  76. alias gap='git add --patch'
  77. alias gm='git merge'
  78. compdef _git gm=git-merge
  79. alias grh='git reset HEAD'
  80. alias grhh='git reset HEAD --hard'
  81. alias gclean='git reset --hard && git clean -dfx'
  82. alias gwc='git whatchanged -p --abbrev-commit --pretty=medium'
  83. # Sign and verify commits with GPG
  84. alias gcs='git commit -S'
  85. compdef _git gcs=git-commit
  86. alias gsps='git show --pretty=short --show-signature'
  87. compdef _git gsps=git-show
  88. # Sign and verify tags with GPG
  89. alias gts='git tag -s'
  90. compdef _git gts=git-tag
  91. alias gvt='git verify-tag'
  92. compdef _git gvt=git verify-tag
  93. #remove the gf alias
  94. #alias gf='git ls-files | grep'
  95. alias gpoat='git push origin --all && git push origin --tags'
  96. alias gmt='git mergetool --no-prompt'
  97. compdef _git gm=git-mergetool
  98. alias gg='git gui citool'
  99. alias gga='git gui citool --amend'
  100. alias gk='gitk --all --branches'
  101. alias gsts='git stash show --text'
  102. alias gsta='git stash'
  103. alias gstp='git stash pop'
  104. alias gstd='git stash drop'
  105. # Will cd into the top of the current repository
  106. # or submodule.
  107. alias grt='cd $(git rev-parse --show-toplevel || echo ".")'
  108. # Git and svn mix
  109. alias git-svn-dcommit-push='git svn dcommit && git push github master:svntrunk'
  110. compdef git-svn-dcommit-push=git
  111. alias gsr='git svn rebase'
  112. alias gsd='git svn dcommit'
  113. #
  114. # Will return the current branch name
  115. # Usage example: git pull origin $(current_branch)
  116. #
  117. function current_branch() {
  118. if [ ! -d .git ]; then return; fi
  119. ref=$(git symbolic-ref HEAD 2> /dev/null) || \
  120. ref=$(git rev-parse --short HEAD 2> /dev/null) || return
  121. echo ${ref#refs/heads/}
  122. }
  123. function current_repository() {
  124. if [ ! -d .git ]; then return; fi
  125. ref=$(git symbolic-ref HEAD 2> /dev/null) || \
  126. ref=$(git rev-parse --short HEAD 2> /dev/null) || return
  127. echo $(git remote -v | cut -d':' -f 2)
  128. }
  129. # these aliases take advantage of the previous function
  130. alias ggpull='git pull origin $(current_branch)'
  131. compdef ggpull=git
  132. alias ggpur='git pull --rebase origin $(current_branch)'
  133. compdef ggpur=git
  134. alias ggpush='git push origin $(current_branch)'
  135. compdef ggpush=git
  136. alias ggpnp='git pull origin $(current_branch) && git push origin $(current_branch)'
  137. compdef ggpnp=git
  138. # Pretty log messages
  139. function _git_log_prettily(){
  140. if ! [ -z $1 ]; then
  141. git log --pretty=$1
  142. fi
  143. }
  144. alias glp="_git_log_prettily"
  145. compdef _git glp=git-log
  146. # Work In Progress (wip)
  147. # These features allow to pause a branch development and switch to another one (wip)
  148. # When you want to go back to work, just unwip it
  149. #
  150. # This function return a warning if the current branch is a wip
  151. function work_in_progress() {
  152. if $(git log -n 1 2>/dev/null | grep -q -c "\-\-wip\-\-"); then
  153. echo "WIP!!"
  154. fi
  155. }
  156. # these alias commit and uncomit wip branches
  157. alias gwip='git add -A; git ls-files --deleted -z | xargs -r0 git rm; git commit -m "--wip--"'
  158. alias gunwip='git log -n 1 | grep -q -c "\-\-wip\-\-" && git reset HEAD~1'
  159. # these alias ignore changes to file
  160. alias gignore='git update-index --assume-unchanged'
  161. alias gunignore='git update-index --no-assume-unchanged'
  162. # list temporarily ignored files
  163. alias gignored='git ls-files -v | grep "^[[:lower:]]"'