mercurial.plugin.zsh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. # aliases
  2. alias hga='hg add'
  3. alias hgc='hg commit'
  4. alias hgca='hg commit --amend'
  5. alias hgci='hg commit --interactive'
  6. alias hgb='hg branch'
  7. alias hgba='hg branches'
  8. alias hgbk='hg bookmarks'
  9. alias hgco='hg checkout'
  10. alias hgd='hg diff'
  11. alias hged='hg diffmerge'
  12. alias hgp='hg push'
  13. alias hgs='hg status'
  14. alias hgsl='hg log --limit 20 --template "{node|short} | {date|isodatesec} | {author|person}: {desc|strip|firstline}\n" '
  15. alias hgun='hg resolve --list'
  16. # pull and update
  17. alias hgi='hg incoming'
  18. alias hgl='hg pull -u'
  19. alias hglr='hg pull --rebase'
  20. alias hgo='hg outgoing'
  21. alias hglg='hg log --stat -v'
  22. alias hglgp='hg log --stat -p -v'
  23. function hgic() {
  24. hg incoming "$@" | grep "changeset" | wc -l
  25. }
  26. function hgoc() {
  27. hg outgoing "$@" | grep "changeset" | wc -l
  28. }
  29. # functions
  30. function hg_root() {
  31. local dir="$PWD"
  32. while [[ "$dir" != "/" ]]; do
  33. if [[ -d "$dir/.hg" ]]; then
  34. echo "$dir"
  35. return 0
  36. fi
  37. dir="${dir:h}"
  38. done
  39. return 1
  40. }
  41. function in_hg() {
  42. hg_root >/dev/null
  43. }
  44. function hg_get_branch_name() {
  45. local dir
  46. if ! dir=$(hg_root); then
  47. return
  48. fi
  49. if [[ ! -f "$dir/.hg/branch" ]]; then
  50. echo default
  51. return
  52. fi
  53. echo "$(<"$dir/.hg/branch")"
  54. }
  55. function hg_get_bookmark_name() {
  56. local dir
  57. if ! dir=$(hg_root); then
  58. return
  59. fi
  60. if [[ ! -f "$dir/.hg/bookmarks.current" ]]; then
  61. return
  62. fi
  63. echo "$(<"$dir/.hg/bookmarks.current")"
  64. }
  65. function hg_prompt_info {
  66. local dir branch dirty
  67. if ! dir=$(hg_root); then
  68. return
  69. fi
  70. if [[ ! -f "$dir/.hg/branch" ]]; then
  71. branch=default
  72. else
  73. branch="$(<"$dir/.hg/branch")"
  74. fi
  75. dirty="$(hg_dirty)"
  76. echo "${ZSH_THEME_HG_PROMPT_PREFIX}${branch:gs/%/%%}${dirty}${ZSH_THEME_HG_PROMPT_SUFFIX}"
  77. }
  78. function hg_dirty {
  79. local hg_status
  80. if ! hg_status="$(hg status -mar 2>/dev/null)"; then
  81. return
  82. fi
  83. # grep exits with 0 when dirty
  84. if command grep -Eq '^\s*[ACDIM!?L]' <<< "$hg_status"; then
  85. echo $ZSH_THEME_HG_PROMPT_DIRTY
  86. return
  87. fi
  88. echo $ZSH_THEME_HG_PROMPT_CLEAN
  89. }