]>
Commit | Line | Data |
---|---|---|
1 | prompt_arrows_help() { | |
2 | cat << EOF | |
3 | prompt arrows <right|2line> <normal> <prompt> <ssh> <urgent> <comment> <dir> <unwritable> | |
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 | ||
8 | All other parameters are Zsh PROMPT_SUBST color values wrapped in '%F{}'. | |
9 | ||
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 | ||
15 | ||
16 | Defaults are white, green, random, red, blue, yellow, and darkyellow | |
17 | respectively. | |
18 | ||
19 | EOF | |
20 | } | |
21 | ||
22 | local prompt_arrows_vimode= | |
23 | ||
24 | function prompt_arrows_setup() { | |
25 | prompt_opts=( cr sp percent subst ) | |
26 | ||
27 | ||
28 | # XXX: no checks for color terminal or if escapes work, except for echotc | |
29 | local m n p s r c d u | |
30 | #TODO remove n? | |
31 | m=${1:-2line} # Mode | |
32 | n=${2:-white} # Normal | |
33 | p=${3:-green} # Prompt | |
34 | s=${4:-random} # Ssh prompt | |
35 | r=${5:-red} # uRgent | |
36 | c=${6:-blue} # Comment | |
37 | d=${7:-yellow} # Dir | |
38 | u=${8:-darkyellow} # Unwritable | |
39 | ||
40 | # [AC]CURSED COMMAND | |
41 | # concatenate the numerical values of each letter of the hostname, | |
42 | # moduloing by the number of possible colors. | |
43 | x=$(echotc Co) | |
44 | [[ -z $x ]] && x=8 | |
45 | local generated=$(uname -n | od -An -td1 | awk -F' ' \ | |
46 | "{for (i=1; i<=NF; i++) {sum+=1; sum*=\$i; sum%=$(echotc Co)} print sum}") | |
47 | [[ $p = random ]] && p=$generated | |
48 | [[ $s = random ]] && s=$generated | |
49 | ||
50 | # use ssh color if connected | |
51 | [[ -v SSH_CLIENT ]] && p=$s | |
52 | ||
53 | local clock="%F{$n}%T%f" dirvcs="%F{$d}"'${vcs_info_msg_0_:-%~}'"%f" | |
54 | # XXX: linux only | |
55 | local battery=/sys/class/power_supply/BAT0/capacity | |
56 | [[ -e "$battery" ]] && clock+=' $(cat $battery)%%' | |
57 | local vicol='%F{${${prompt_arrows_vimode:+'"$r"'}:-'"$c"'}}' | |
58 | local hist="%F{$n}%h" | |
59 | case "$m" { | |
60 | 2line) | |
61 | PROMPT="%f $hist $clock $dirvcs"$'\n'"%F{$c}>>> " | |
62 | unset RPROMPT | |
63 | ;; | |
64 | right) | |
65 | RPROMPT="$dirvcs $clock" | |
66 | PROMPT="%F{$c}>>> $hist" | |
67 | ;; | |
68 | *) | |
69 | echo "Unknown prompt mode $m" | |
70 | return | |
71 | ;; | |
72 | } | |
73 | PROMPT="$PROMPT%(1j,%F{$c}%j,)$vicol%#%F{$p}%n%F{$n}@%F{$p}%2m%(?..%F{$n}/%F{$r}\$?)%F{$n}: " | |
74 | POSTEDIT="$(print -P "%F{$n}%f")" | |
75 | autoload -Uz vcs_info | |
76 | zstyle ':vcs_info:git*' formats "%c%u%%F{$p}%r/%b%%F{$n}/%%F{$d}%S%%f" | |
77 | zstyle ':vcs_info:git*' actionformats "%%F{$r}(%a)%f %c%u%%F{$p}%r/%b%f/%%F{$d}%S%f" | |
78 | zstyle ':vcs_info:git*' stagedstr "%F{$c}+" | |
79 | zstyle ':vcs_info:git*' unstagedstr "%F{$r}*" | |
80 | ||
81 | # add-zsh-hook should have already been autoloaded by promptinit | |
82 | add-zsh-hook precmd prompt_arrows_precmd | |
83 | add-zsh-hook preexec prompt_arrows_preexec | |
84 | autoload -Uz add-zle-hook-widget | |
85 | add-zle-hook-widget line-init prompt_arrows_keymap_select | |
86 | add-zle-hook-widget keymap-select prompt_arrows_keymap_select | |
87 | } | |
88 | ||
89 | # change color based on zle vi mode | |
90 | function prompt_arrows_keymap_select { | |
91 | prompt_arrows_vimode="${KEYMAP:/(main|viins)/}" | |
92 | zle reset-prompt | |
93 | } | |
94 | ||
95 | function prompt_arrows_precmd { | |
96 | vcs_info | |
97 | } | |
98 | ||
99 | function prompt_arrows_preexec { | |
100 | print -Pn "%F{red}<<<%f " | |
101 | } | |
102 | ||
103 | function prompt_arrows_preview { | |
104 | if (( ! $#* )); then | |
105 | prompt_preview_theme arrows 2line | |
106 | print '\n' | |
107 | prompt_preview_theme arrows right | |
108 | ||
109 | else | |
110 | prompt_preview_theme arrows "$@" | |
111 | ||
112 | fi | |
113 | } | |
114 | ||
115 | prompt_arrows_setup "$@" | |
116 | # vim: set et fenc=utf-8 ft=zsh sts=4 sw=4 ts=8 tw=0 : |