mercurial.plugin.zsh 1.6 KB

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