mercurial.plugin.zsh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. alias hgca='hg commit --amend'
  18. # list unresolved files (since hg does not list unmerged files in the status command)
  19. alias hgun='hg resolve --list'
  20. function in_hg() {
  21. if [[ -d .hg ]] || $(hg summary > /dev/null 2>&1); then
  22. echo 1
  23. fi
  24. }
  25. function hg_get_branch_name() {
  26. if [ $(in_hg) ]; then
  27. echo $(hg branch)
  28. fi
  29. }
  30. function hg_prompt_info {
  31. if [ $(in_hg) ]; then
  32. _DISPLAY=$(hg_get_branch_name)
  33. echo "$ZSH_PROMPT_BASE_COLOR$ZSH_THEME_HG_PROMPT_PREFIX\
  34. $ZSH_THEME_REPO_NAME_COLOR$_DISPLAY$ZSH_PROMPT_BASE_COLOR$ZSH_PROMPT_BASE_COLOR$(hg_dirty)$ZSH_THEME_HG_PROMPT_SUFFIX$ZSH_PROMPT_BASE_COLOR"
  35. unset _DISPLAY
  36. fi
  37. }
  38. function hg_dirty_choose {
  39. if [ $(in_hg) ]; then
  40. hg status 2> /dev/null | command grep -Eq '^\s*[ACDIM!?L]'
  41. if [ $pipestatus[-1] -eq 0 ]; then
  42. # Grep exits with 0 when "One or more lines were selected", return "dirty".
  43. echo $1
  44. else
  45. # Otherwise, no lines were found, or an error occurred. Return clean.
  46. echo $2
  47. fi
  48. fi
  49. }
  50. function hg_dirty {
  51. hg_dirty_choose $ZSH_THEME_HG_PROMPT_DIRTY $ZSH_THEME_HG_PROMPT_CLEAN
  52. }
  53. function hgic() {
  54. hg incoming "$@" | grep "changeset" | wc -l
  55. }
  56. function hgoc() {
  57. hg outgoing "$@" | grep "changeset" | wc -l
  58. }