3 prompt ds6 <right|2line> <normal> <prompt> <ssh> <urgent> <comment> <dir> <unwritable>
5 The first parameter determines whether or not to use right-aligned status
6 text, or to put it above the command line.
8 If 'prompt' or 'ssh' are 'random', their respective value will be
9 procedurally generated using the machine hostname as a seed; if the
10 machine is connected to SSH, the 'prompt' value will be replaced with
13 All other parameters are Zsh PROMPT_SUBST color values wrapped in '%F{}'.
15 Defaults are white, green, random, red, blue, yellow, and darkyellow
21 local prompt_ds6_vimode=
23 function prompt_ds6_setup() {
24 # TODO: check for color terminal. never will use B&W term but still a XXX
25 local n p _p s r c d u
27 m="${1:-2line}" # Mode
28 n="${2:-white}" # Normal
29 p="${3:-green}" # Prompt
30 s="${4:-random}" # Ssh prompt
31 r="${5:-red}" # uRgent
32 c="${6:-blue}" # Comment
33 d="${7:-yellow}" # Dir
34 u="${8:-darkyellow}" # Unwritable
37 # concatenate the numerical values of each letter of the hostname,
38 # moduloing by the number of possible colors.
39 generated=$(uname -n | od -An -td1 | awk -F' ' \
40 "{for (i=1; i<=NF; i++) {sum+=1; sum*=\$i; sum%=`echotc Co`} print sum}")
41 [[ "$p" = 'random' ]] && p=$generated
42 [[ "$s" = 'random' ]] && s=$generated
44 # use ssh color if connected
45 p="${${SSH_CLIENT+$s}:-$p}"
47 local clock="%F{$n}%T%f" dirvcs="%F{$d}"'${vcs_info_msg_0_:-%~}'"%f"
48 local battery=/sys/class/power_supply/BAT0/capacity
49 [[ -e "$battery" ]] && clock+=" `cat $battery`%%"
50 local vicol='%F{${${prompt_ds6_vimode:+'"$r"'}:-'"$c"'}}'
53 PROMPT="%f $clock $dirvcs"$'\n'"%F{$c}>>> "
57 RPROMPT="$dirvcs $clock"
61 echo "Unknown prompt mode $m"
65 PROMPT="$PROMPT%(1j,%F{$c}%j,)$vicol%#%F{$p}%n%F{$n}@%F{$p}%2m%(?..%F{$n}/%F{$r}\$?)%F{$n}: "
66 POSTEDIT="`print -P "%F{$n}%f"`"
67 zstyle ':vcs_info:git*' formats "%c%u%%F{$p}%r/%b%%F{$n}/%%F{$d}%S%%f"
68 zstyle ':vcs_info:git*' actionformats "%%F{$r}(%a)%f %c%u%%F{$p}%r/%b%f/%%F{$d}%S%f"
69 zstyle ':vcs_info:git*' stagedstr "%F{$c}+"
70 zstyle ':vcs_info:git*' unstagedstr "%F{$r}*"
72 add-zsh-hook precmd prompt_ds6_precmd
73 add-zsh-hook preexec prompt_ds6_preexec
75 zle -A zle-line-init zle-keymap-select
78 # change color based on zle vi mode
79 function zle-line-init {
80 prompt_ds6_vimode="${KEYMAP:/(main|viins)/}"
84 function prompt_ds6_precmd {
85 # TODO: check if vcs_info is autoloaded
89 function prompt_ds6_preexec {
90 print -Pn "%F{red}<<<%f "
94 # vim: set et fenc=utf-8 ft=zsh sts=4 sw=4 ts=8 tw=0 :