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.

57 lines
1.5 KiB

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