git.plugin.zsh 7.8 KB

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