git.zsh 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # preferred git shortcuts, not in the git plugin
  2. #compare the provided version of git to the version installed and on path
  3. #prints 1 if input version <= installed version
  4. #prints -1 otherwise
  5. function git_compare_version() {
  6. local INPUT_GIT_VERSION=$1;
  7. local INSTALLED_GIT_VERSION
  8. INPUT_GIT_VERSION=(${(s/./)INPUT_GIT_VERSION});
  9. INSTALLED_GIT_VERSION=($(command git --version 2>/dev/null));
  10. INSTALLED_GIT_VERSION=(${(s/./)INSTALLED_GIT_VERSION[3]});
  11. for i in {1..3}; do
  12. if [[ $INSTALLED_GIT_VERSION[$i] -gt $INPUT_GIT_VERSION[$i] ]]; then
  13. echo 1
  14. return 0
  15. fi
  16. if [[ $INSTALLED_GIT_VERSION[$i] -lt $INPUT_GIT_VERSION[$i] ]]; then
  17. echo -1
  18. return 0
  19. fi
  20. done
  21. echo 1
  22. return 0
  23. }
  24. POST_1_8_3_GIT=$(git_compare_version "1.8.3")
  25. unset -f git_compare_version
  26. # As of git 1.8.3 decorations can be coloured automatically according to what
  27. # they are i.e. tags, branches, etc.
  28. if [[ $POST_1_8_3_GIT -gt 0 ]]; then
  29. DECO_COLOUR='%C(auto)'
  30. else
  31. DECO_COLOUR='%Cgreen'
  32. fi
  33. GIT_LOG_FORMAT='"format:%C(yellow)%h %Creset%ad %Cblue%an:'$DECO_COLOUR'%d %Creset%s"'
  34. alias ga.='git add -A .'
  35. alias gap='git add -p'
  36. alias gbav='git branch -av'
  37. alias gbd='git branch -D'
  38. alias gbv='git branch -v'
  39. alias gcob='git checkout -b'
  40. alias gds='git diff --staged'
  41. alias gf='git fetch --all --tags && git fetch --all --prune'
  42. alias ggpush='git push origin $(current_branch)'
  43. compdef ggpush=git
  44. # standard log with train tracks.
  45. alias gl='git log --graph --date=short --pretty='$GIT_LOG_FORMAT
  46. # search through commit DIFFs for particular text (pick ax)
  47. # does NOT search commit MESSAGES - use `--grep` for that.
  48. alias glS='git log -S'
  49. alias gla='gl --all'
  50. # concise branch and tag log with train tracks.
  51. alias glb='gl --simplify-by-decoration'
  52. alias glh='gl --max-count=15'
  53. alias glp='git log --graph --decorate --patch'
  54. alias gls='git log --graph --decorate --stat'
  55. alias gr='git reset'
  56. alias grh='git reset --hard'
  57. alias grs='git reset --soft'
  58. alias gs='git status'
  59. # git submodule management
  60. alias gsm='git submodule'
  61. alias gsmpull='git submodule foreach git pull'
  62. alias gsmup='git submodule sync && git submodule update --init'
  63. # useful for finding parent commit for a given commit hash
  64. alias gsr='git show --format=raw'
  65. # setup tracking for origin.
  66. alias track='git branch --set-upstream-to origin/$(current_branch) && git fetch'
  67. # useful omz git plugin ones include:
  68. # ga, gc, gco, gb, gba, gm, grhh, grb, gwip, gunwip
  69. #
  70. # ggpush has been removed from oh-my-zsh!
  71. # ggpush translates into `git push origin <current branch>`.