fossil.plugin.zsh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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