initial
[zsh.git] / .zsh / 20_Prompts.zsh
1 # -*- mode: sh;-*-
2
3 # how often should the periodic function be called? I take every 30seconds here.
4 # Important: The periodic function is only called when
5 # - the defined time $PERIOD elapsed
6 # *AND*
7 # - the prompt gets displayed again!
8 # Its not cron-like "execute this really every 30s in the background"!
9 #
10 # But for sanity reasons - make this conditional on existance of tools, but never
11 # overwrite existing values
12 if which yacpi > /dev/null; then
13 (( ${+PERIOD} )) || export PERIOD=30
14 LAPTOP=yacpi
15 elif which ibam > /dev/null; then
16 (( ${+PERIOD} )) || export PERIOD=30
17 LAPTOP=ibam
18 else
19 (( ${+PERIOD} )) || unset PERIOD
20 unset LAPTOP
21 fi
22
23 # the following is for prompt and gets modified in periodic()
24 typeset -A ACPIDISPLAY
25 # I know, this stuff is currently made only for my laptop. But right now i cant be bothered
26 # to make it more generic
27 PR_SLASH='${PR_YELLOW}/${PR_RED}'
28 TOOLONG=0
29
30 # I call periodic here one time to have all the variables it sets initialized. Or
31 # the first prompt would look ugly.
32 periodic
33
34 # gather version control information for inclusion in a prompt
35 # we will only be using one variable, so let the code know now.
36 autoload -Uz vcs_info && vcs_info
37 zstyle ':vcs_info:*' max-exports 1
38 zstyle ':vcs_info:*' disable cdv darcs mtn tla hg
39 zstyle ':vcs_info:*' use-prompt-escapes
40 zstyle ':vcs_info:*' use_simple
41
42 # change vcs_info formats for the prompt
43 if [[ "$TERM" == dumb ]] ; then
44 zstyle ':vcs_info:*' actionformats "(%s%)-[%b|%a] "
45 zstyle ':vcs_info:*' formats "(%s%)-[%b] "
46 else
47 # these are the same, just with a lot of colours:
48 # zstyle ':vcs_info:*' actionformats "$%s${PR_YELLOW})${PR_CYAN}-${PR_YELLOW}[${PR_GREEN}%b${PR_YELLOW}|${PR_RED}%a${PR_YELLOW}]${PR_NO_COLOUR}"
49 zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat "%b%{$fg[red]%}:%{$fg[yellow]%}%r"
50 zstyle ':vcs_info:git*' formats "%{$fg[yellow]%}%s %{$reset_color%} %{$fg[green]%}%b%{$reset_color%}%m%u%c%{$reset_color%} "
51 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%} "
52 fi
53
54 PR_BARLENGTH=0
55
56 setprompt
57
58 # See if our (effective) group has changed at all. (For instance, we're
59 # in a subshell that is setgid.) This happens when i type "newgrp group"
60 # for whatever reason
61 # I haven't put this in the precmd function because I don't expect
62 # my effective group to change over the life of the shell. It can if
63 # I'm running with root privileges, but I deliberately don't use zsh for
64 # root in any case, because that encourages me to not use root for
65 # anything I don't have to use it for.
66 if [[ "$ORIGGID" != "$EGID" ]]; then
67 # Set for either normal prompt and xterm title bars.
68 GNAME=$(grpname $EGID)
69 if [[ "$TERM" = "xterm" ]]; then
70 psvar[5]=":$GNAME"
71 else
72 psvar[5]="g[$GNAME] "
73 fi
74 else
75 psvar[5]=
76 fi