mercurial.plugin.zsh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 in_hg() {
  24. if $(hg branch > /dev/null 2>&1); then
  25. echo 1
  26. fi
  27. }
  28. function hg_get_branch_name() {
  29. branch=`hg branch 2>/dev/null`
  30. if [ $? -eq 0 ]; then
  31. echo $branch
  32. fi
  33. unset branch
  34. }
  35. function hg_prompt_info {
  36. local info rev branch dirty
  37. if ! info=$(hg id --id --branch 2>/dev/null); then
  38. return
  39. fi
  40. rev="${info[(w)1]}"
  41. branch="${${info[(w)2]}:gs/%/%%}"
  42. if [[ "$rev" = *+ ]]; then
  43. dirty="$ZSH_THEME_HG_PROMPT_DIRTY"
  44. else
  45. dirty="$ZSH_THEME_HG_PROMPT_CLEAN"
  46. fi
  47. echo "${ZSH_THEME_HG_PROMPT_PREFIX}${branch}${dirty}${ZSH_THEME_HG_PROMPT_SUFFIX}"
  48. }
  49. function hg_dirty_choose {
  50. hg status -mar 2> /dev/null | command grep -Eq '^\s*[ACDIM!?L]'
  51. if [ $? -eq 0 ]; then
  52. if [ $pipestatus[-1] -eq 0 ]; then
  53. # Grep exits with 0 when "One or more lines were selected", return "dirty".
  54. echo $1
  55. return
  56. fi
  57. fi
  58. echo $2
  59. }
  60. function hg_dirty {
  61. hg_dirty_choose $ZSH_THEME_HG_PROMPT_DIRTY $ZSH_THEME_HG_PROMPT_CLEAN
  62. }
  63. function hgic() {
  64. hg incoming "$@" | grep "changeset" | wc -l
  65. }
  66. function hgoc() {
  67. hg outgoing "$@" | grep "changeset" | wc -l
  68. }
  69. function hg_get_bookmark_name() {
  70. if [ $(in_hg) ]; then
  71. echo $(hg id -B)
  72. fi
  73. }