my xfce4 dotfiles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
2.3 KiB

3 years ago
  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. # Do nothing if clean / dirty settings aren't defined
  80. if [[ -z "$ZSH_THEME_HG_PROMPT_DIRTY" && -z "$ZSH_THEME_HG_PROMPT_CLEAN" ]]; then
  81. return
  82. fi
  83. # Check if there are modifications
  84. local hg_status
  85. if [[ "$DISABLE_UNTRACKED_FILES_DIRTY" = true ]]; then
  86. if ! hg_status="$(hg status -q 2>/dev/null)"; then
  87. return
  88. fi
  89. else
  90. if ! hg_status="$(hg status 2>/dev/null)"; then
  91. return
  92. fi
  93. fi
  94. # grep exits with 0 when dirty
  95. if command grep -Eq '^\s*[ACDIMR!?L].*$' <<< "$hg_status"; then
  96. echo $ZSH_THEME_HG_PROMPT_DIRTY
  97. return
  98. fi
  99. echo $ZSH_THEME_HG_PROMPT_CLEAN
  100. }