fossil.plugin.zsh
1461 bytes
1_FOSSIL_PROMPT=""
2
3# Prefix at the very beginning of the prompt, before the branch name
4ZSH_THEME_FOSSIL_PROMPT_PREFIX="%{$fg_bold[blue]%}fossil:(%{$fg_bold[red]%}"
5
6# At the very end of the prompt
7ZSH_THEME_FOSSIL_PROMPT_SUFFIX="%{$fg_bold[blue]%})"
8
9# Text to display if the branch is dirty
10ZSH_THEME_FOSSIL_PROMPT_DIRTY=" %{$fg_bold[red]%}✖"
11
12# Text to display if the branch is clean
13ZSH_THEME_FOSSIL_PROMPT_CLEAN=" %{$fg_bold[green]%}✔"
14
15function fossil_prompt_info() {
16 local branch=$(fossil branch current 2>&1)
17
18 # if we're not in a fossil repo, don't show anything
19 ! command grep -q "use --repo" <<< "$branch" || return
20
21 local changes=$(fossil changes)
22 local dirty="$ZSH_THEME_FOSSIL_PROMPT_CLEAN"
23
24 if [[ -n "$changes" ]]; then
25 dirty="$ZSH_THEME_FOSSIL_PROMPT_DIRTY"
26 fi
27
28 printf '%s %s %s %s %s' \
29 "$ZSH_THEME_FOSSIL_PROMPT_PREFIX" \
30 "${branch:gs/%/%%}" \
31 "$ZSH_THEME_FOSSIL_PROMPT_SUFFIX" \
32 "$dirty" \
33 "%{$reset_color%}"
34}
35
36function _fossil_prompt () {
37 local current=`echo $PROMPT $RPROMPT | grep fossil`
38
39 if [ "$_FOSSIL_PROMPT" = "" -o "$current" = "" ]; then
40 local _prompt=${PROMPT}
41 local _rprompt=${RPROMPT}
42
43 local is_prompt=`echo $PROMPT | grep git`
44
45 if [ "$is_prompt" = "" ]; then
46 RPROMPT="$_rprompt"'$(fossil_prompt_info)'
47 else
48 PROMPT="$_prompt"'$(fossil_prompt_info) '
49 fi
50
51 _FOSSIL_PROMPT="1"
52 fi
53}
54
55autoload -U add-zsh-hook
56add-zsh-hook precmd _fossil_prompt