git.plugin.zsh 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 gau='git add --update'
  42. alias gb='git branch'
  43. alias gba='git branch -a'
  44. alias gbd='git branch -d'
  45. alias gbda='git branch --no-color --merged | command grep -vE "^(\*|\s*(master|develop|dev)\s*$)" | command xargs -n 1 git branch -d'
  46. alias gbl='git blame -b -w'
  47. alias gbnm='git branch --no-merged'
  48. alias gbr='git branch --remote'
  49. alias gbs='git bisect'
  50. alias gbsb='git bisect bad'
  51. alias gbsg='git bisect good'
  52. alias gbsr='git bisect reset'
  53. alias gbss='git bisect start'
  54. alias gc='git commit -v'
  55. alias gc!='git commit -v --amend'
  56. alias gcn!='git commit -v --no-edit --amend'
  57. alias gca='git commit -v -a'
  58. alias gca!='git commit -v -a --amend'
  59. alias gcan!='git commit -v -a --no-edit --amend'
  60. alias gcans!='git commit -v -a -s --no-edit --amend'
  61. alias gcam='git commit -a -m'
  62. alias gcsm='git commit -s -m'
  63. alias gcb='git checkout -b'
  64. alias gcf='git config --list'
  65. alias gcl='git clone --recursive'
  66. alias gclean='git clean -fd'
  67. alias gpristine='git reset --hard && git clean -dfx'
  68. alias gcm='git checkout master'
  69. alias gcd='git checkout develop'
  70. alias gcmsg='git commit -m'
  71. alias gco='git checkout'
  72. alias gcount='git shortlog -sn'
  73. compdef _git gcount
  74. alias gcp='git cherry-pick'
  75. alias gcpa='git cherry-pick --abort'
  76. alias gcpc='git cherry-pick --continue'
  77. alias gcs='git commit -S'
  78. alias gd='git diff'
  79. alias gdca='git diff --cached'
  80. alias gdct='git describe --tags `git rev-list --tags --max-count=1`'
  81. alias gdt='git diff-tree --no-commit-id --name-only -r'
  82. alias gdw='git diff --word-diff'
  83. gdv() { git diff -w "$@" | view - }
  84. compdef _git gdv=git-diff
  85. alias gf='git fetch'
  86. alias gfa='git fetch --all --prune'
  87. alias gfo='git fetch origin'
  88. function gfg() { git ls-files | grep $@ }
  89. compdef _grep gfg
  90. alias gg='git gui citool'
  91. alias gga='git gui citool --amend'
  92. ggf() {
  93. [[ "$#" != 1 ]] && local b="$(git_current_branch)"
  94. git push --force origin "${b:=$1}"
  95. }
  96. compdef _git ggf=git-checkout
  97. ggl() {
  98. if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then
  99. git pull origin "${*}"
  100. else
  101. [[ "$#" == 0 ]] && local b="$(git_current_branch)"
  102. git pull origin "${b:=$1}"
  103. fi
  104. }
  105. compdef _git ggl=git-checkout
  106. ggp() {
  107. if [[ "$#" != 0 ]] && [[ "$#" != 1 ]]; then
  108. git push origin "${*}"
  109. else
  110. [[ "$#" == 0 ]] && local b="$(git_current_branch)"
  111. git push origin "${b:=$1}"
  112. fi
  113. }
  114. compdef _git ggp=git-checkout
  115. ggpnp() {
  116. if [[ "$#" == 0 ]]; then
  117. ggl && ggp
  118. else
  119. ggl "${*}" && ggp "${*}"
  120. fi
  121. }
  122. compdef _git ggpnp=git-checkout
  123. ggu() {
  124. [[ "$#" != 1 ]] && local b="$(git_current_branch)"
  125. git pull --rebase origin "${b:=$1}"
  126. }
  127. compdef _git ggu=git-checkout
  128. alias ggpur='ggu'
  129. compdef _git ggpur=git-checkout
  130. alias ggpull='git pull origin $(git_current_branch)'
  131. compdef _git ggpull=git-checkout
  132. alias ggpush='git push origin $(git_current_branch)'
  133. compdef _git ggpush=git-checkout
  134. alias ggsup='git branch --set-upstream-to=origin/$(git_current_branch)'
  135. alias gpsup='git push --set-upstream origin $(git_current_branch)'
  136. alias ghh='git help'
  137. alias gignore='git update-index --assume-unchanged'
  138. alias gignored='git ls-files -v | grep "^[[:lower:]]"'
  139. alias git-svn-dcommit-push='git svn dcommit && git push github master:svntrunk'
  140. compdef _git git-svn-dcommit-push=git
  141. alias gk='\gitk --all --branches'
  142. compdef _git gk='gitk'
  143. alias gke='\gitk --all $(git log -g --pretty=%h)'
  144. compdef _git gke='gitk'
  145. alias gl='git pull'
  146. alias glg='git log --stat'
  147. alias glgp='git log --stat -p'
  148. alias glgg='git log --graph'
  149. alias glgga='git log --graph --decorate --all'
  150. alias glgm='git log --graph --max-count=10'
  151. alias glo='git log --oneline --decorate'
  152. alias glol="git log --graph --pretty='%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
  153. alias glola="git log --graph --pretty='%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --all"
  154. alias glog='git log --oneline --decorate --graph'
  155. alias gloga='git log --oneline --decorate --graph --all'
  156. alias glp="_git_log_prettily"
  157. compdef _git glp=git-log
  158. alias gm='git merge'
  159. alias gmom='git merge origin/master'
  160. alias gmt='git mergetool --no-prompt'
  161. alias gmtvim='git mergetool --no-prompt --tool=vimdiff'
  162. alias gmum='git merge upstream/master'
  163. alias gp='git push'
  164. alias gpd='git push --dry-run'
  165. alias gpoat='git push origin --all && git push origin --tags'
  166. compdef _git gpoat=git-push
  167. alias gpu='git push upstream'
  168. alias gpv='git push -v'
  169. alias gr='git remote'
  170. alias gra='git remote add'
  171. alias grb='git rebase'
  172. alias grba='git rebase --abort'
  173. alias grbc='git rebase --continue'
  174. alias grbi='git rebase -i'
  175. alias grbm='git rebase master'
  176. alias grbs='git rebase --skip'
  177. alias grh='git reset HEAD'
  178. alias grhh='git reset HEAD --hard'
  179. alias grmv='git remote rename'
  180. alias grrm='git remote remove'
  181. alias grset='git remote set-url'
  182. alias grt='cd $(git rev-parse --show-toplevel || echo ".")'
  183. alias gru='git reset --'
  184. alias grup='git remote update'
  185. alias grv='git remote -v'
  186. alias gsb='git status -sb'
  187. alias gsd='git svn dcommit'
  188. alias gsi='git submodule init'
  189. alias gsps='git show --pretty=short --show-signature'
  190. alias gsr='git svn rebase'
  191. alias gss='git status -s'
  192. alias gst='git status'
  193. alias gsta='git stash save'
  194. alias gstaa='git stash apply'
  195. alias gstc='git stash clear'
  196. alias gstd='git stash drop'
  197. alias gstl='git stash list'
  198. alias gstp='git stash pop'
  199. alias gsts='git stash show --text'
  200. alias gsu='git submodule update'
  201. alias gts='git tag -s'
  202. alias gtv='git tag | sort -V'
  203. alias gunignore='git update-index --no-assume-unchanged'
  204. alias gunwip='git log -n 1 | grep -q -c "\-\-wip\-\-" && git reset HEAD~1'
  205. alias gup='git pull --rebase'
  206. alias gupv='git pull --rebase -v'
  207. alias glum='git pull upstream master'
  208. alias gwch='git whatchanged -p --abbrev-commit --pretty=medium'
  209. alias gwip='git add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify -m "--wip-- [skip ci]"'