git.plugin.zsh 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. # Query/use custom command for `git`.
  2. zstyle -s ":vcs_info:git:*:-all-" "command" _omz_git_git_cmd
  3. : ${_omz_git_git_cmd:=git}
  4. #
  5. # Functions
  6. #
  7. # The name of the current branch
  8. # Back-compatibility wrapper for when this function was defined here in
  9. # the plugin, before being pulled in to core lib/git.zsh as git_current_branch()
  10. # to fix the core -> git plugin dependency.
  11. function current_branch() {
  12. git_current_branch
  13. }
  14. # The list of remotes
  15. function current_repository() {
  16. if ! $_omz_git_git_cmd rev-parse --is-inside-work-tree &> /dev/null; then
  17. return
  18. fi
  19. echo $($_omz_git_git_cmd remote -v | cut -d':' -f 2)
  20. }
  21. # Pretty log messages
  22. function _git_log_prettily(){
  23. if ! [ -z $1 ]; then
  24. git log --pretty=$1
  25. fi
  26. }
  27. # Warn if the current branch is a WIP
  28. function work_in_progress() {
  29. if $(git log -n 1 2>/dev/null | grep -q -c "\-\-wip\-\-"); then
  30. echo "WIP!!"
  31. fi
  32. }
  33. #
  34. # Aliases
  35. # (sorted alphabetically)
  36. #
  37. alias g='git'
  38. alias ga='git add'
  39. alias gaa='git add --all'
  40. alias gapa='git add --patch'
  41. alias gb='git branch'
  42. alias gba='git branch -a'
  43. alias gbda='git branch --merged | command grep -vE "^(\*|\s*master\s*$)" | command xargs -n 1 git branch -d'
  44. alias gbl='git blame -b -w'
  45. alias gbnm='git branch --no-merged'
  46. alias gbr='git branch --remote'
  47. alias gbs='git bisect'
  48. alias gbsb='git bisect bad'
  49. alias gbsg='git bisect good'
  50. alias gbsr='git bisect reset'
  51. alias gbss='git bisect start'
  52. alias gc='git commit -v'
  53. alias gc!='git commit -v --amend'
  54. alias gca='git commit -v -a'
  55. alias gca!='git commit -v -a --amend'
  56. alias gcan!='git commit -v -a -s --no-edit --amend'
  57. alias gcam='git commit -a -m'
  58. alias gcb='git checkout -b'
  59. alias gcf='git config --list'
  60. alias gcl='git clone --recursive'
  61. alias gclean='git clean -fd'
  62. alias gpristine='git reset --hard && git clean -dfx'
  63. alias gcm='git checkout master'
  64. alias gcmsg='git commit -m'
  65. alias gco='git checkout'
  66. alias gcount='git shortlog -sn'
  67. compdef gcount=git
  68. alias gcp='git cherry-pick'
  69. alias gcs='git commit -S'
  70. alias gd='git diff'
  71. alias gdca='git diff --cached'
  72. alias gdct='git describe --tags `git rev-list --tags --max-count=1`'
  73. alias gdt='git diff-tree --no-commit-id --name-only -r'
  74. gdv() { git diff -w "$@" | view - }
  75. compdef _git gdv=git-diff
  76. alias gdw='git diff --word-diff'
  77. alias gf='git fetch'
  78. alias gfa='git fetch --all --prune'
  79. function gfg() { git ls-files | grep $@ }
  80. compdef gfg=grep
  81. alias gfo='git fetch origin'
  82. alias gg='git gui citool'
  83. alias gga='git gui citool --amend'
  84. ggf() {
  85. [[ "$#" != 1 ]] && local b="$(git_current_branch)"
  86. git push --force origin "${b:=$1}"
  87. }
  88. compdef _git ggf=git-checkout
  89. ggl() {
  90. if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then
  91. git pull origin "${*}"
  92. else
  93. [[ "$#" == 0 ]] && local b="$(git_current_branch)"
  94. git pull origin "${b:=$1}"
  95. fi
  96. }
  97. compdef _git ggl=git-checkout
  98. alias ggpull='git pull origin $(git_current_branch)'
  99. compdef _git ggpull=git-checkout
  100. ggp() {
  101. if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then
  102. git push origin "${*}"
  103. else
  104. [[ "$#" == 0 ]] && local b="$(git_current_branch)"
  105. git push origin "${b:=$1}"
  106. fi
  107. }
  108. compdef _git ggp=git-checkout
  109. alias ggpush='git push origin $(git_current_branch)'
  110. compdef _git ggpush=git-checkout
  111. ggpnp() {
  112. if [[ "$#" == 0 ]]; then
  113. ggl && ggp
  114. else
  115. ggl "${*}" && ggp "${*}"
  116. fi
  117. }
  118. compdef _git ggpnp=git-checkout
  119. alias ggsup='git branch --set-upstream-to=origin/$(git_current_branch)'
  120. ggu() {
  121. [[ "$#" != 1 ]] && local b="$(git_current_branch)"
  122. git pull --rebase origin "${b:=$1}"
  123. }
  124. compdef _git ggu=git-checkout
  125. alias ggpur='ggu'
  126. compdef _git ggpur=git-checkout
  127. alias gignore='git update-index --assume-unchanged'
  128. alias gignored='git ls-files -v | grep "^[[:lower:]]"'
  129. alias git-svn-dcommit-push='git svn dcommit && git push github master:svntrunk'
  130. compdef git-svn-dcommit-push=git
  131. alias gk='\gitk --all --branches'
  132. compdef _git gk='gitk'
  133. alias gke='\gitk --all $(git log -g --pretty=format:%h)'
  134. compdef _git gke='gitk'
  135. alias gl='git pull'
  136. alias glg='git log --stat'
  137. alias glgp='git log --stat -p'
  138. alias glgg='git log --graph'
  139. alias glgga='git log --graph --decorate --all'
  140. alias glgm='git log --graph --max-count=10'
  141. alias glo='git log --oneline --decorate'
  142. alias glol="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
  143. alias glola="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --all"
  144. alias glog='git log --oneline --decorate --graph'
  145. alias glp="_git_log_prettily"
  146. compdef _git glp=git-log
  147. alias gm='git merge'
  148. alias gmom='git merge origin/master'
  149. alias gmt='git mergetool --no-prompt'
  150. alias gmtvim='git mergetool --no-prompt --tool=vimdiff'
  151. alias gmum='git merge upstream/master'
  152. alias gp='git push'
  153. alias gpd='git push --dry-run'
  154. alias gpoat='git push origin --all && git push origin --tags'
  155. compdef _git gpoat=git-push
  156. alias gpu='git push upstream'
  157. alias gpv='git push -v'
  158. alias gr='git remote'
  159. alias gra='git remote add'
  160. alias grb='git rebase'
  161. alias grba='git rebase --abort'
  162. alias grbc='git rebase --continue'
  163. alias grbi='git rebase -i'
  164. alias grbm='git rebase master'
  165. alias grbs='git rebase --skip'
  166. alias grh='git reset HEAD'
  167. alias grhh='git reset HEAD --hard'
  168. alias grmv='git remote rename'
  169. alias grrm='git remote remove'
  170. alias grset='git remote set-url'
  171. alias grt='cd $(git rev-parse --show-toplevel || echo ".")'
  172. alias gru='git reset --'
  173. alias grup='git remote update'
  174. alias grv='git remote -v'
  175. alias gsb='git status -sb'
  176. alias gsd='git svn dcommit'
  177. alias gsi='git submodule init'
  178. alias gsps='git show --pretty=short --show-signature'
  179. alias gsr='git svn rebase'
  180. alias gss='git status -s'
  181. alias gst='git status'
  182. alias gsta='git stash'
  183. alias gstaa='git stash apply'
  184. alias gstd='git stash drop'
  185. alias gstl='git stash list'
  186. alias gstp='git stash pop'
  187. alias gsts='git stash show --text'
  188. alias gsu='git submodule update'
  189. alias gts='git tag -s'
  190. alias gtv='git tag | sort -V'
  191. alias gunignore='git update-index --no-assume-unchanged'
  192. alias gunwip='git log -n 1 | grep -q -c "\-\-wip\-\-" && git reset HEAD~1'
  193. alias gup='git pull --rebase'
  194. alias gupv='git pull --rebase -v'
  195. alias glum='git pull upstream master'
  196. alias gwch='git whatchanged -p --abbrev-commit --pretty=medium'
  197. alias gwip='git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit -m "--wip--"'