Rework of my prompt
[zsh.git] / .zsh / 20_Prompts.zsh
1 # -*- mode: sh;-*-
2
3 # Harr. "Borrowing" from the grml zshell config, this now supports
4 # a much nicer prompt setup, should zsh be recent enough to support it.
5 # That is, anything >= 4.3.7, the older ones keep using my old way.
6 if is437; then
7 if zrcautoload promptinit && promptinit 2>/dev/null ; then
8 zstyle ':prompt:ganneff' vcs_info true
9 zstyle ':prompt:ganneff' colors true
10 zstyle ':prompt:ganneff' nicelines true
11 zstyle ':prompt:ganneff' battery none
12 zstyle ':prompt:ganneff:right:setup' use-rprompt true
13 zstyle ':prompt:ganneff:left:full:setup' items \
14 ulcorner line openbracket user at host pts closebracket line history \
15 flexline openbracket path closebracket line urcorner newline \
16 llcorner line rc openbracket time closebracket line vcs line change-root pipe space
17 zstyle ':prompt:ganneff:right:full:setup' items \
18 pipe line openbracket date closebracket line lrcorner
19 zstyle ':prompt:ganneff:left:small:setup' items \
20 ulcorner line openbracket user at host closebracket line openbracket path closebracket newline \
21 llcorner line rc openbracket time closebracket line vcs line pipe space
22
23 prompt ganneff
24 fi
25 else
26 # And the old way
27 # how often should the periodic function be called? I take every 30seconds here.
28 # Important: The periodic function is only called when
29 # - the defined time $PERIOD elapsed
30 # *AND*
31 # - the prompt gets displayed again!
32 # Its not cron-like "execute this really every 30s in the background"!
33 #
34 # But for sanity reasons - make this conditional on existance of tools, but never
35 # overwrite existing values
36 if which yacpi > /dev/null; then
37 (( ${+PERIOD} )) || export PERIOD=30
38 LAPTOP=yacpi
39 elif which ibam > /dev/null; then
40 (( ${+PERIOD} )) || export PERIOD=30
41 LAPTOP=ibam
42 else
43 (( ${+PERIOD} )) || unset PERIOD
44 unset LAPTOP
45 fi
46
47 # the following is for prompt and gets modified in periodic()
48 typeset -A ACPIDISPLAY
49 # I know, this stuff is currently made only for my laptop. But right now i cant be bothered
50 # to make it more generic
51 PR_SLASH='${PR_YELLOW}/${PR_RED}'
52 TOOLONG=0
53
54 # I call periodic here one time to have all the variables it sets initialized. Or
55 # the first prompt would look ugly.
56 periodic
57
58 # gather version control information for inclusion in a prompt
59 # we will only be using one variable, so let the code know now.
60 if is439 && zrcautoload vcs_info && vcs_info; then
61 zstyle ':vcs_info:*' max-exports 1
62 zstyle ':vcs_info:*' disable cdv darcs mtn tla hg fossil p4
63 zstyle ':vcs_info:*' use-prompt-escapes
64 zstyle ':vcs_info:*' use_simple
65 zstyle ':vcs_info:*' stagedstr "!"
66 zstyle ':vcs_info:*' unstagedstr "?"
67 zstyle ':vcs_info:*' check-for-changes true
68
69 # change vcs_info formats for the prompt
70 if [[ "$TERM" == dumb ]]; then
71 zstyle ':vcs_info:*' actionformats "(%s%)-[%b|%a] "
72 zstyle ':vcs_info:*' formats "(%s%)-[%b] "
73 else
74 # these are the same, just with a lot of colours:
75 # zstyle ':vcs_info:*' actionformats "$%s${PR_YELLOW})${PR_CYAN}-${PR_YELLOW}[${PR_GREEN}%b${PR_YELLOW}|${PR_RED}%a${PR_YELLOW}]${PR_NO_COLOUR}"
76 zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat "%b%{$fg[red]%}:%{$fg[yellow]%}%r"
77 zstyle ':vcs_info:git*' formats "%{$fg[yellow]%}%s %{$reset_color%} %{$fg[green]%}%b%{$reset_color%}%m%u%c%{$reset_color%} "
78 zstyle ':vcs_info:git*' actionformats "%{$fg[yellow]%}%s%{$reset_color%} %{$fg[green]%}%b%{$reset_color%} $fg[red]%}(%a)%{$reset_color%} %m%u%c%{$reset_color%} "
79 fi
80 fi
81
82 PR_BARLENGTH=0
83
84 setprompt
85
86 # See if our (effective) group has changed at all. (For instance, we're
87 # in a subshell that is setgid.) This happens when i type "newgrp group"
88 # for whatever reason
89 # I haven't put this in the precmd function because I don't expect
90 # my effective group to change over the life of the shell. It can if
91 # I'm running with root privileges, but I deliberately don't use zsh for
92 # root in any case, because that encourages me to not use root for
93 # anything I don't have to use it for.
94 if [[ "$ORIGGID" != "$EGID" ]]; then
95 # Set for either normal prompt and xterm title bars.
96 GNAME=$(grpname $EGID)
97 if [[ "$TERM" = "xterm" ]]; then
98 psvar[5]=":$GNAME"
99 else
100 psvar[5]="g[$GNAME] "
101 fi
102 else
103 psvar[5]=
104 fi
105 fi