git.plugin.zsh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. # Aliases
  2. alias g='git'
  3. compdef g=git
  4. alias gst='git status'
  5. compdef _git gst=git-status
  6. alias gd='git diff'
  7. compdef _git gd=git-diff
  8. alias gdc='git diff --cached'
  9. compdef _git gdc=git-diff
  10. alias gl='git pull'
  11. compdef _git gl=git-pull
  12. alias gup='git pull --rebase'
  13. compdef _git gup=git-fetch
  14. alias gp='git push'
  15. compdef _git gp=git-push
  16. alias gd='git diff'
  17. gdv() { git diff -w "$@" | view - }
  18. compdef _git gdv=git-diff
  19. alias gc='git commit -v'
  20. compdef _git gc=git-commit
  21. alias gc!='git commit -v --amend'
  22. compdef _git gc!=git-commit
  23. alias gca='git commit -v -a'
  24. compdef _git gc=git-commit
  25. alias gca!='git commit -v -a --amend'
  26. compdef _git gca!=git-commit
  27. alias gcmsg='git commit -m'
  28. compdef _git gcmsg=git-commit
  29. alias gco='git checkout'
  30. compdef _git gco=git-checkout
  31. alias gcm='git checkout master'
  32. alias gr='git remote'
  33. compdef _git gr=git-remote
  34. alias grv='git remote -v'
  35. compdef _git grv=git-remote
  36. alias grmv='git remote rename'
  37. compdef _git grmv=git-remote
  38. alias grrm='git remote remove'
  39. compdef _git grrm=git-remote
  40. alias grset='git remote set-url'
  41. compdef _git grset=git-remote
  42. alias grup='git remote update'
  43. compdef _git grset=git-remote
  44. alias grbi='git rebase -i'
  45. compdef _git grbi=git-rebase
  46. alias grbc='git rebase --continue'
  47. compdef _git grbc=git-rebase
  48. alias grba='git rebase --abort'
  49. compdef _git grba=git-rebase
  50. alias gb='git branch'
  51. compdef _git gb=git-branch
  52. alias gba='git branch -a'
  53. compdef _git gba=git-branch
  54. alias gcount='git shortlog -sn'
  55. compdef gcount=git
  56. alias gcl='git config --list'
  57. alias gcp='git cherry-pick'
  58. compdef _git gcp=git-cherry-pick
  59. alias glg='git log --stat --max-count=10'
  60. compdef _git glg=git-log
  61. alias glgg='git log --graph --max-count=10'
  62. compdef _git glgg=git-log
  63. alias glgga='git log --graph --decorate --all'
  64. compdef _git glgga=git-log
  65. alias glo='git log --oneline'
  66. compdef _git glo=git-log
  67. alias gss='git status -s'
  68. compdef _git gss=git-status
  69. alias ga='git add'
  70. compdef _git ga=git-add
  71. alias gm='git merge'
  72. compdef _git gm=git-merge
  73. alias grh='git reset HEAD'
  74. alias grhh='git reset HEAD --hard'
  75. alias gclean='git reset --hard && git clean -dfx'
  76. alias gwc='git whatchanged -p --abbrev-commit --pretty=medium'
  77. #remove the gf alias
  78. #alias gf='git ls-files | grep'
  79. alias gpoat='git push origin --all && git push origin --tags'
  80. alias gmt='git mergetool --no-prompt'
  81. compdef _git gm=git-mergetool
  82. alias gg='git gui citool'
  83. alias gga='git gui citool --amend'
  84. alias gk='gitk --all --branches'
  85. alias gsts='git stash show --text'
  86. alias gsta='git stash'
  87. alias gstp='git stash pop'
  88. alias gstd='git stash drop'
  89. # Will cd into the top of the current repository
  90. # or submodule.
  91. alias grt='cd $(git rev-parse --show-toplevel || echo ".")'
  92. # Git and svn mix
  93. alias git-svn-dcommit-push='git svn dcommit && git push github master:svntrunk'
  94. compdef git-svn-dcommit-push=git
  95. alias gsr='git svn rebase'
  96. alias gsd='git svn dcommit'
  97. #
  98. # Will return the current branch name
  99. # Usage example: git pull origin $(current_branch)
  100. #
  101. function current_branch() {
  102. ref=$(git symbolic-ref HEAD 2> /dev/null) || \
  103. ref=$(git rev-parse --short HEAD 2> /dev/null) || return
  104. echo ${ref#refs/heads/}
  105. }
  106. function current_repository() {
  107. ref=$(git symbolic-ref HEAD 2> /dev/null) || \
  108. ref=$(git rev-parse --short HEAD 2> /dev/null) || return
  109. echo $(git remote -v | cut -d':' -f 2)
  110. }
  111. # these aliases take advantage of the previous function
  112. alias ggpull='git pull origin $(current_branch)'
  113. compdef ggpull=git
  114. alias ggpur='git pull --rebase origin $(current_branch)'
  115. compdef ggpur=git
  116. alias ggpush='git push origin $(current_branch)'
  117. compdef ggpush=git
  118. alias ggpnp='git pull origin $(current_branch) && git push origin $(current_branch)'
  119. compdef ggpnp=git
  120. # Pretty log messages
  121. function _git_log_prettily(){
  122. if ! [ -z $1 ]; then
  123. git log --pretty=$1
  124. fi
  125. }
  126. alias glp="_git_log_prettily"
  127. compdef _git glp=git-log
  128. # Work In Progress (wip)
  129. # These features allow to pause a branch development and switch to another one (wip)
  130. # When you want to go back to work, just unwip it
  131. #
  132. # This function return a warning if the current branch is a wip
  133. function work_in_progress() {
  134. if $(git log -n 1 2>/dev/null | grep -q -c wip); then
  135. echo "WIP!!"
  136. fi
  137. }
  138. # these alias commit and uncomit wip branches
  139. alias gwip='git add -A; git ls-files --deleted -z | xargs -0 git rm; git commit -m "wip"'
  140. alias gunwip='git log -n 1 | grep -q -c wip && git reset HEAD~1'