fossil.plugin.zsh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 branch=$(fossil branch current 2>&1)
  12. # if we're not in a fossil repo, don't show anything
  13. ! command grep -q "use --repo" <<< "$branch" || return
  14. local changes=$(fossil changes)
  15. local dirty="$ZSH_THEME_FOSSIL_PROMPT_CLEAN"
  16. if [[ -n "$changes" ]]; then
  17. dirty="$ZSH_THEME_FOSSIL_PROMPT_DIRTY"
  18. fi
  19. printf '%s %s %s %s %s' \
  20. "$ZSH_THEME_FOSSIL_PROMPT_PREFIX" \
  21. "${branch:gs/%/%%}" \
  22. "$ZSH_THEME_FOSSIL_PROMPT_SUFFIX" \
  23. "$dirty" \
  24. "%{$reset_color%}"
  25. }
  26. function _fossil_prompt () {
  27. local current=`echo $PROMPT $RPROMPT | grep fossil`
  28. if [ "$_FOSSIL_PROMPT" = "" -o "$current" = "" ]; then
  29. local _prompt=${PROMPT}
  30. local _rprompt=${RPROMPT}
  31. local is_prompt=`echo $PROMPT | grep git`
  32. if [ "$is_prompt" = "" ]; then
  33. RPROMPT="$_rprompt"'$(fossil_prompt_info)'
  34. else
  35. PROMPT="$_prompt"'$(fossil_prompt_info) '
  36. fi
  37. _FOSSIL_PROMPT="1"
  38. fi
  39. }
  40. autoload -U add-zsh-hook
  41. add-zsh-hook precmd _fossil_prompt