git.plugin.zsh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 gl='git pull'
  9. compdef _git gl=git-pull
  10. alias gup='git pull --rebase'
  11. compdef _git gup=git-fetch
  12. alias gp='git push'
  13. compdef _git gp=git-push
  14. alias gd='git diff'
  15. gdv() { git diff -w "$@" | view - }
  16. compdef _git gdv=git-diff
  17. alias gc='git commit -v'
  18. compdef _git gc=git-commit
  19. alias gc!='git commit -v --amend'
  20. compdef _git gc!=git-commit
  21. alias gca='git commit -v -a'
  22. compdef _git gc=git-commit
  23. alias gca!='git commit -v -a --amend'
  24. compdef _git gca!=git-commit
  25. alias gcmsg='git commit -m'
  26. compdef _git gcmsg=git-commit
  27. alias gco='git checkout'
  28. compdef _git gco=git-checkout
  29. alias gcm='git checkout master'
  30. alias gr='git remote'
  31. compdef _git gr=git-remote
  32. alias grv='git remote -v'
  33. compdef _git grv=git-remote
  34. alias grmv='git remote rename'
  35. compdef _git grmv=git-remote
  36. alias grrm='git remote remove'
  37. compdef _git grrm=git-remote
  38. alias grset='git remote set-url'
  39. compdef _git grset=git-remote
  40. alias grup='git remote update'
  41. compdef _git grset=git-remote
  42. alias grbi='git rebase -i'
  43. compdef _git grbi=git-rebase
  44. alias grbc='git rebase --continue'
  45. compdef _git grbc=git-rebase
  46. alias grba='git rebase --abort'
  47. compdef _git grba=git-rebase
  48. alias gb='git branch'
  49. compdef _git gb=git-branch
  50. alias gba='git branch -a'
  51. compdef _git gba=git-branch
  52. alias gcount='git shortlog -sn'
  53. compdef gcount=git
  54. alias gcl='git config --list'
  55. alias gcp='git cherry-pick'
  56. compdef _git gcp=git-cherry-pick
  57. alias glg='git log --stat --max-count=5'
  58. compdef _git glg=git-log
  59. alias glgg='git log --graph --max-count=5'
  60. compdef _git glgg=git-log
  61. alias glgga='git log --graph --decorate --all'
  62. compdef _git glgga=git-log
  63. alias glo='git log --oneline'
  64. compdef _git glo=git-log
  65. alias gss='git status -s'
  66. compdef _git gss=git-status
  67. alias ga='git add'
  68. compdef _git ga=git-add
  69. alias gm='git merge'
  70. compdef _git gm=git-merge
  71. alias grh='git reset HEAD'
  72. alias grhh='git reset HEAD --hard'
  73. alias gclean='git reset --hard && git clean -dfx'
  74. alias gwc='git whatchanged -p --abbrev-commit --pretty=medium'
  75. alias gf='git ls-files | grep'
  76. alias gpoat='git push origin --all && git push origin --tags'
  77. alias gmt='git mergetool --no-prompt'
  78. compdef _git gm=git-mergetool
  79. alias gg='git gui citool'
  80. alias gga='git gui citool --amend'
  81. alias gk='gitk --all --branches'
  82. alias gsts='git stash show --text'
  83. # Will cd into the top of the current repository
  84. # or submodule.
  85. alias grt='cd $(git rev-parse --show-toplevel || echo ".")'
  86. # Git and svn mix
  87. alias git-svn-dcommit-push='git svn dcommit && git push github master:svntrunk'
  88. compdef git-svn-dcommit-push=git
  89. alias gsr='git svn rebase'
  90. alias gsd='git svn dcommit'
  91. #
  92. # Will return the current branch name
  93. # Usage example: git pull origin $(current_branch)
  94. #
  95. function current_branch() {
  96. ref=$(git symbolic-ref HEAD 2> /dev/null) || \
  97. ref=$(git rev-parse --short HEAD 2> /dev/null) || return
  98. echo ${ref#refs/heads/}
  99. }
  100. function current_repository() {
  101. ref=$(git symbolic-ref HEAD 2> /dev/null) || \
  102. ref=$(git rev-parse --short HEAD 2> /dev/null) || return
  103. echo $(git remote -v | cut -d':' -f 2)
  104. }
  105. # these aliases take advantage of the previous function
  106. alias ggpull='git pull origin $(current_branch)'
  107. compdef ggpull=git
  108. alias ggpur='git pull --rebase origin $(current_branch)'
  109. compdef ggpur=git
  110. alias ggpush='git push origin $(current_branch)'
  111. compdef ggpush=git
  112. alias ggpnp='git pull origin $(current_branch) && git push origin $(current_branch)'
  113. compdef ggpnp=git
  114. # Pretty log messages
  115. function _git_log_prettily(){
  116. if ! [ -z $1 ]; then
  117. git log --pretty=$1
  118. fi
  119. }
  120. alias glp="_git_log_prettily"
  121. compdef _git glp=git-log