git.plugin.zsh 6.7 KB

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