fossil.plugin.zsh 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. _FOSSIL_PROMPT=""
  2. # Prefix at the very beginning of the prompt, before the branch name
  3. ZSH_THEME_FOSSIL_PROMPT_PREFIX="%{$fg_bold[blue]%}fossil:(%{$fg_bold[red]%}"
  4. # At the very end of the prompt
  5. ZSH_THEME_FOSSIL_PROMPT_SUFFIX="%{$fg_bold[blue]%})"
  6. # Text to display if the branch is dirty
  7. ZSH_THEME_FOSSIL_PROMPT_DIRTY=" %{$fg_bold[red]%}✖"
  8. # Text to display if the branch is clean
  9. ZSH_THEME_FOSSIL_PROMPT_CLEAN=" %{$fg_bold[green]%}✔"
  10. function fossil_prompt_info () {
  11. local _OUTPUT=`fossil branch 2>&1`
  12. local _STATUS=`echo $_OUTPUT | grep "use --repo"`
  13. if [ "$_STATUS" = "" ]; then
  14. local _EDITED=`fossil changes`
  15. local _EDITED_SYM="$ZSH_THEME_FOSSIL_PROMPT_CLEAN"
  16. local _BRANCH=`echo $_OUTPUT | grep "* " | sed 's/* //g'`
  17. if [ "$_EDITED" != "" ]; then
  18. _EDITED_SYM="$ZSH_THEME_FOSSIL_PROMPT_DIRTY"
  19. fi
  20. echo "$ZSH_THEME_FOSSIL_PROMPT_PREFIX" \
  21. "$_BRANCH" \
  22. "$ZSH_THEME_FOSSIL_PROMPT_SUFFIX" \
  23. "$_EDITED_SYM"\
  24. "%{$reset_color%}"
  25. fi
  26. }
  27. function _fossil_get_command_list () {
  28. fossil help -a | grep -v "Usage|Common|This is"
  29. }
  30. function _fossil () {
  31. local context state state_descr line
  32. typeset -A opt_args
  33. _arguments \
  34. '1: :->command'\
  35. '2: :->subcommand'
  36. case $state in
  37. command)
  38. local _OUTPUT=`fossil branch 2>&1 | grep "use --repo"`
  39. if [ "$_OUTPUT" = "" ]; then
  40. compadd `_fossil_get_command_list`
  41. else
  42. compadd clone init import help version
  43. fi
  44. ;;
  45. subcommand)
  46. if [ "$words[2]" = "help" ]; then
  47. compadd `_fossil_get_command_list`
  48. else
  49. compcall -D
  50. fi
  51. ;;
  52. esac
  53. }
  54. function _fossil_prompt () {
  55. local current=`echo $PROMPT $RPROMPT | grep fossil`
  56. if [ "$_FOSSIL_PROMPT" = "" -o "$current" = "" ]; then
  57. local _prompt=${PROMPT}
  58. local _rprompt=${RPROMPT}
  59. local is_prompt=`echo $PROMPT | grep git`
  60. if [ "$is_prompt" = "" ]; then
  61. export RPROMPT="$_rprompt"'$(fossil_prompt_info)'
  62. else
  63. export PROMPT="$_prompt"'$(fossil_prompt_info) '
  64. fi
  65. _FOSSIL_PROMPT="1"
  66. fi
  67. }
  68. compdef _fossil fossil
  69. autoload -U add-zsh-hook
  70. add-zsh-hook precmd _fossil_prompt