git.plugin.zsh 7.2 KB

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