]> git.sev.monster Git - dotfiles.git/blame_incremental - base/.zsh/prompt_ds6_setup
update firefox theming
[dotfiles.git] / base / .zsh / prompt_ds6_setup
... / ...
CommitLineData
1prompt_ds6_help() {
2 cat << EOF
3prompt ds6 <right|2line> <normal> <prompt> <ssh> <urgent> <comment> <dir> <unwritable>
4
5The first parameter determines whether or not to use right-aligned status
6text, or to put it above the command line.
7
8If 'prompt' or 'ssh' are 'random', their respective value will be
9procedurally generated using the machine hostname as a seed; if the
10machine is connected to SSH, the 'prompt' value will be replaced with
11the 'ssh' value.
12
13All other parameters are Zsh PROMPT_SUBST color values wrapped in '%F{}'.
14
15Defaults are white, green, random, red, blue, yellow, and darkyellow
16respectively.
17
18EOF
19}
20
21local prompt_ds6_vimode=
22
23function 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
78function zle-line-init {
79 prompt_ds6_vimode="${KEYMAP:/(main|viins)/}"
80 zle reset-prompt
81}
82
83function prompt_ds6_precmd() {
84 # TODO: check if vcs_info is autoloaded
85 vcs_info
86}
87
88prompt_ds6_setup "$@"
89# vim: set et fenc=utf-8 ft=zsh sts=4 sw=4 ts=8 tw=0 :
This page took 0.030267 seconds and 4 git commands to generate.