]>
Commit | Line | Data |
---|---|---|
fab483dd | 1 | prompt_ds6_help() { |
2 | cat << EOF | |
3 | prompt ds6 <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 | 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 | |
11 | the 'ssh' value. | |
12 | ||
13 | All other parameters are Zsh PROMPT_SUBST color values wrapped in '%F{}'. | |
14 | ||
15 | Defaults are white, green, random, red, blue, yellow, and darkyellow | |
16 | respectively. | |
17 | ||
18 | EOF | |
19 | } | |
20 | ||
21 | local prompt_ds6_vimode= | |
22 | ||
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 | |
26 | #TODO remove n? | |
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 | |
35 | ||
36 | # [AC]CURSED COMMAND | |
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 | |
43 | ||
44 | # use ssh color if connected | |
45 | p="${${SSH_CLIENT+$s}:-$p}" | |
46 | ||
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"'}}' | |
51 | case "$m" { | |
52 | 2line) | |
53 | PROMPT="%f $clock $dirvcs"$'\n'"%F{$c}>>> " | |
54 | unset RPROMPT | |
55 | ;; | |
56 | right) | |
57 | RPROMPT="$dirvcs $clock" | |
58 | PROMPT="" | |
59 | ;; | |
60 | *) | |
61 | echo "Unknown prompt mode $m" | |
62 | return | |
63 | ;; | |
64 | } | |
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}*" | |
71 | ||
72 | add-zsh-hook precmd prompt_ds6_precmd | |
73 | zle -N zle-line-init | |
74 | zle -A zle-line-init zle-keymap-select | |
75 | } | |
76 | ||
77 | # change color based on zle vi mode | |
78 | function zle-line-init { | |
79 | prompt_ds6_vimode="${KEYMAP:/(main|viins)/}" | |
80 | zle reset-prompt | |
81 | } | |
82 | ||
83 | function prompt_ds6_precmd() { | |
84 | # TODO: check if vcs_info is autoloaded | |
85 | vcs_info | |
86 | } | |
87 | ||
88 | prompt_ds6_setup "$@" | |
89 | # vim: set et fenc=utf-8 ft=zsh sts=4 sw=4 ts=8 tw=0 : |