mercurial.plugin.zsh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # Mercurial
  2. alias hgc='hg commit'
  3. alias hgb='hg branch'
  4. alias hgba='hg branches'
  5. alias hgbk='hg bookmarks'
  6. alias hgco='hg checkout'
  7. alias hgd='hg diff'
  8. alias hged='hg diffmerge'
  9. # pull and update
  10. alias hgi='hg incoming'
  11. alias hgl='hg pull -u'
  12. alias hglr='hg pull --rebase'
  13. alias hgo='hg outgoing'
  14. alias hgp='hg push'
  15. alias hgs='hg status'
  16. alias hgsl='hg log --limit 20 --template "{node|short} | {date|isodatesec} | {author|user}: {desc|strip|firstline}\n" '
  17. # this is the 'git commit --amend' equivalent
  18. alias hgca='hg qimport -r tip ; hg qrefresh -e ; hg qfinish tip'
  19. # list unresolved files (since hg does not list unmerged files in the status command)
  20. alias hgun='hg resolve --list'
  21. function in_hg() {
  22. if [[ -d .hg ]] || $(hg summary > /dev/null 2>&1); then
  23. echo 1
  24. fi
  25. }
  26. function hg_get_branch_name() {
  27. if [ $(in_hg) ]; then
  28. echo $(hg branch)
  29. fi
  30. }
  31. function hg_prompt_info {
  32. if [ $(in_hg) ]; then
  33. _DISPLAY=$(hg_get_branch_name)
  34. echo "$ZSH_PROMPT_BASE_COLOR$ZSH_THEME_HG_PROMPT_PREFIX\
  35. $ZSH_THEME_REPO_NAME_COLOR$_DISPLAY$ZSH_PROMPT_BASE_COLOR$ZSH_THEME_HG_PROMPT_SUFFIX$ZSH_PROMPT_BASE_COLOR$(hg_dirty)$ZSH_PROMPT_BASE_COLOR"
  36. unset _DISPLAY
  37. fi
  38. }
  39. function hg_dirty_choose {
  40. if [ $(in_hg) ]; then
  41. hg status 2> /dev/null | grep -Eq '^\s*[ACDIM!?L]'
  42. if [ $pipestatus[-1] -eq 0 ]; then
  43. # Grep exits with 0 when "One or more lines were selected", return "dirty".
  44. echo $1
  45. else
  46. # Otherwise, no lines were found, or an error occurred. Return clean.
  47. echo $2
  48. fi
  49. fi
  50. }
  51. function hg_dirty {
  52. hg_dirty_choose $ZSH_THEME_HG_PROMPT_DIRTY $ZSH_THEME_HG_PROMPT_CLEAN
  53. }
  54. function hgic() {
  55. hg incoming "$@" | grep "changeset" | wc -l
  56. }
  57. function hgoc() {
  58. hg outgoing "$@" | grep "changeset" | wc -l
  59. }