5 prompt arrows <right|2line> <normal> <prompt> <ssh> <urgent> <comment> <dir> <unwritable>
7 The first parameter determines whether or not to use right-aligned status
8 text, or to put it above the command line.
10 All other parameters are Zsh PROMPT_SUBST color values wrapped in '%F{}'.
12 If 'prompt' or 'ssh' are 'random', their respective value will be
13 procedurally generated using the machine hostname as a seed; if the
14 machine is connected to SSH, the 'prompt' value will be replaced with
18 Defaults are white, green, random, red, blue, yellow, and darkyellow
24 local prompt_arrows_vimode=
26 function prompt_arrows_setup() {
27 prompt_opts=( cr sp percent subst )
30 # XXX: no checks for color terminal or if escapes work, except for echotc
34 n=${2:-white} # Normal
35 p=${3:-green} # Prompt
36 s=${4:-random} # Ssh prompt
38 c=${6:-blue} # Comment
40 u=${8:-darkyellow} # Unwritable
43 # concatenate the numerical values of each letter of the hostname,
44 # moduloing by the number of possible colors.
47 local generated=$(uname -n | od -An -td1 | awk -F' ' \
48 "{for (i=1; i<=NF; i++) {sum+=1; sum*=\$i; sum%=$(echotc Co)} print sum}")
49 [[ $p = random ]] && p=$generated
50 [[ $s = random ]] && s=$generated
52 # use ssh color if connected
53 [[ -v SSH_CLIENT ]] && p=$s
55 local clock="%F{$n}%T%f" dirvcs="%F{$d}"'${vcs_info_msg_0_:-%~}'"%f"
57 local battery=/sys/class/power_supply/BAT0/capacity
58 [[ -e "$battery" ]] && clock+=' $(cat "'"$battery"'")%%'
59 local vicol='%F{${${prompt_arrows_vimode:+'"$r"'}:-'"$c"'}}'
63 PROMPT="%f $hist $clock $dirvcs"$'\n'"%F{$c}>>> "
67 RPROMPT="$dirvcs $clock"
68 PROMPT="%F{$c}>>> $hist"
71 echo "Unknown prompt mode $m"
75 PROMPT="$PROMPT%(1j,%F{$c}%j,)$vicol%#%F{$p}%n%F{$n}@%F{$p}%2m%(?..%F{$n}/%F{$r}\$?)%F{$n}: "
76 POSTEDIT="$(print -P "%F{$n}%f")"
78 zstyle ':vcs_info:git*' formats "%c%u%%F{$p}%r/%b%%F{$n}/%%F{$d}%S%%f"
79 zstyle ':vcs_info:git*' actionformats "%%F{$r}(%a)%f %c%u%%F{$p}%r/%b%f/%%F{$d}%S%f"
80 zstyle ':vcs_info:git*' stagedstr "%F{$c}+"
81 zstyle ':vcs_info:git*' unstagedstr "%F{$r}!"
83 # add-zsh-hook should have already been autoloaded by promptinit
84 add-zsh-hook precmd prompt_arrows_precmd
85 autoload -Uz add-zle-hook-widget
86 add-zle-hook-widget line-init prompt_arrows_keymap_select
87 add-zle-hook-widget keymap-select prompt_arrows_keymap_select
90 # change color based on zle vi mode
91 function prompt_arrows_keymap_select {
92 prompt_arrows_vimode="${KEYMAP:/(main|viins)/}"
96 function prompt_arrows_precmd {
100 function prompt_arrows_preview {
102 prompt_preview_theme arrows 2line
104 prompt_preview_theme arrows right
107 prompt_preview_theme arrows "$@"
112 prompt_arrows_setup "$@"