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