]>
Commit | Line | Data |
---|---|---|
4f471013 | 1 | prompt_arrows_help() { |
fab483dd | 2 | cat << EOF |
4f471013 | 3 | prompt arrows <right|2line> <normal> <prompt> <ssh> <urgent> <comment> <dir> <unwritable> |
fab483dd | 4 | |
5 | The first parameter determines whether or not to use right-aligned status | |
6 | text, or to put it above the command line. | |
7 | ||
325a74cd | 8 | All other parameters are Zsh PROMPT_SUBST color values wrapped in '%F{}'. |
9 | ||
fab483dd | 10 | If 'prompt' or 'ssh' are 'random', their respective value will be |
11 | procedurally generated using the machine hostname as a seed; if the | |
12 | machine is connected to SSH, the 'prompt' value will be replaced with | |
13 | the 'ssh' value. | |
14 | ||
fab483dd | 15 | |
16 | Defaults are white, green, random, red, blue, yellow, and darkyellow | |
17 | respectively. | |
18 | ||
19 | EOF | |
20 | } | |
21 | ||
4f471013 | 22 | local prompt_arrows_vimode= |
fab483dd | 23 | |
4f471013 | 24 | function prompt_arrows_setup() { |
fab483dd | 25 | # TODO: check for color terminal. never will use B&W term but still a XXX |
26 | local n p _p s r c d u | |
27 | #TODO remove n? | |
28 | m="${1:-2line}" # Mode | |
29 | n="${2:-white}" # Normal | |
30 | p="${3:-green}" # Prompt | |
31 | s="${4:-random}" # Ssh prompt | |
32 | r="${5:-red}" # uRgent | |
33 | c="${6:-blue}" # Comment | |
34 | d="${7:-yellow}" # Dir | |
35 | u="${8:-darkyellow}" # Unwritable | |
36 | ||
37 | # [AC]CURSED COMMAND | |
38 | # concatenate the numerical values of each letter of the hostname, | |
39 | # moduloing by the number of possible colors. | |
40 | generated=$(uname -n | od -An -td1 | awk -F' ' \ | |
41 | "{for (i=1; i<=NF; i++) {sum+=1; sum*=\$i; sum%=`echotc Co`} print sum}") | |
42 | [[ "$p" = 'random' ]] && p=$generated | |
43 | [[ "$s" = 'random' ]] && s=$generated | |
44 | ||
45 | # use ssh color if connected | |
46 | p="${${SSH_CLIENT+$s}:-$p}" | |
47 | ||
48 | local clock="%F{$n}%T%f" dirvcs="%F{$d}"'${vcs_info_msg_0_:-%~}'"%f" | |
973a2767 | 49 | # XXX: linux only |
fab483dd | 50 | local battery=/sys/class/power_supply/BAT0/capacity |
51 | [[ -e "$battery" ]] && clock+=" `cat $battery`%%" | |
4f471013 | 52 | local vicol='%F{${${prompt_arrows_vimode:+'"$r"'}:-'"$c"'}}' |
973a2767 | 53 | local hist="%F{$n}%h" |
fab483dd | 54 | case "$m" { |
55 | 2line) | |
973a2767 | 56 | PROMPT="%f $hist $clock $dirvcs"$'\n'"%F{$c}>>> " |
fab483dd | 57 | unset RPROMPT |
58 | ;; | |
59 | right) | |
60 | RPROMPT="$dirvcs $clock" | |
973a2767 | 61 | PROMPT="%F{$c}>>> $hist" |
fab483dd | 62 | ;; |
63 | *) | |
64 | echo "Unknown prompt mode $m" | |
65 | return | |
66 | ;; | |
67 | } | |
68 | PROMPT="$PROMPT%(1j,%F{$c}%j,)$vicol%#%F{$p}%n%F{$n}@%F{$p}%2m%(?..%F{$n}/%F{$r}\$?)%F{$n}: " | |
69 | POSTEDIT="`print -P "%F{$n}%f"`" | |
8eb81f95 | 70 | autoload -Uz vcs_info |
fab483dd | 71 | zstyle ':vcs_info:git*' formats "%c%u%%F{$p}%r/%b%%F{$n}/%%F{$d}%S%%f" |
72 | zstyle ':vcs_info:git*' actionformats "%%F{$r}(%a)%f %c%u%%F{$p}%r/%b%f/%%F{$d}%S%f" | |
73 | zstyle ':vcs_info:git*' stagedstr "%F{$c}+" | |
74 | zstyle ':vcs_info:git*' unstagedstr "%F{$r}*" | |
75 | ||
d569f3f7 | 76 | # add-zsh-hook should have already been autoloaded by promptinit |
4f471013 | 77 | add-zsh-hook precmd prompt_arrows_precmd |
78 | add-zsh-hook preexec prompt_arrows_preexec | |
d569f3f7 | 79 | autoload -Uz add-zle-hook-widget |
80 | add-zle-hook-widget line-init prompt_arrows_keymap_select | |
81 | add-zle-hook-widget keymap-select prompt_arrows_keymap_select | |
fab483dd | 82 | } |
83 | ||
84 | # change color based on zle vi mode | |
d569f3f7 | 85 | function prompt_arrows_keymap_select { |
4f471013 | 86 | prompt_arrows_vimode="${KEYMAP:/(main|viins)/}" |
fab483dd | 87 | zle reset-prompt |
88 | } | |
89 | ||
4f471013 | 90 | function prompt_arrows_precmd { |
fab483dd | 91 | vcs_info |
92 | } | |
93 | ||
4f471013 | 94 | function prompt_arrows_preexec { |
116467fd | 95 | print -Pn "%F{red}<<<%f " |
96 | } | |
97 | ||
4f471013 | 98 | prompt_arrows_setup "$@" |
8eb81f95 | 99 | # vim: set et fenc=utf-8 ft=zsh sts=4 sw=4 ts=8 tw=0 : |