git.plugin.zsh 7.1 KB

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