]> git.sev.monster Git - dotfiles.git/blame - base/.zsh/functions/Prompts/prompt_arrows_setup
partially revert zsh refactor, fix zsh conf bugs
[dotfiles.git] / base / .zsh / functions / Prompts / prompt_arrows_setup
CommitLineData
d3712462 1prompt_arrows_help() {
1f53b630 2 cat << EOF
d3712462 3prompt arrows <right|2line> <normal> <prompt> <ssh> <urgent> <comment> <dir> <unwritable>
1f53b630 4
5The first parameter determines whether or not to use right-aligned status
6text, or to put it above the command line.
7
87c38112 8All other parameters are Zsh PROMPT_SUBST color values wrapped in '%F{}'.
9
1f53b630 10If 'prompt' or 'ssh' are 'random', their respective value will be
11procedurally generated using the machine hostname as a seed; if the
12machine is connected to SSH, the 'prompt' value will be replaced with
13the 'ssh' value.
14
1f53b630 15
16Defaults are white, green, random, red, blue, yellow, and darkyellow
17respectively.
18
19EOF
20}
21
d3712462 22local prompt_arrows_vimode=
1f53b630 23
d3712462 24function prompt_arrows_setup() {
1f53b630 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"
49 local battery=/sys/class/power_supply/BAT0/capacity
50 [[ -e "$battery" ]] && clock+=" `cat $battery`%%"
d3712462 51 local vicol='%F{${${prompt_arrows_vimode:+'"$r"'}:-'"$c"'}}'
1f53b630 52 case "$m" {
53 2line)
54 PROMPT="%f $clock $dirvcs"$'\n'"%F{$c}>>> "
55 unset RPROMPT
56 ;;
57 right)
58 RPROMPT="$dirvcs $clock"
81c3957e 59 PROMPT="%F{$c}>>> "
1f53b630 60 ;;
61 *)
62 echo "Unknown prompt mode $m"
63 return
64 ;;
65 }
66 PROMPT="$PROMPT%(1j,%F{$c}%j,)$vicol%#%F{$p}%n%F{$n}@%F{$p}%2m%(?..%F{$n}/%F{$r}\$?)%F{$n}: "
67 POSTEDIT="`print -P "%F{$n}%f"`"
81c3957e 68 autoload -Uz vcs_info
1f53b630 69 zstyle ':vcs_info:git*' formats "%c%u%%F{$p}%r/%b%%F{$n}/%%F{$d}%S%%f"
70 zstyle ':vcs_info:git*' actionformats "%%F{$r}(%a)%f %c%u%%F{$p}%r/%b%f/%%F{$d}%S%f"
71 zstyle ':vcs_info:git*' stagedstr "%F{$c}+"
72 zstyle ':vcs_info:git*' unstagedstr "%F{$r}*"
73
b133dc92 74 # add-zsh-hook should have already been autoloaded by promptinit
d3712462 75 add-zsh-hook precmd prompt_arrows_precmd
76 add-zsh-hook preexec prompt_arrows_preexec
b133dc92 77 autoload -Uz add-zle-hook-widget
78 add-zle-hook-widget line-init prompt_arrows_keymap_select
79 add-zle-hook-widget keymap-select prompt_arrows_keymap_select
1f53b630 80}
81
82# change color based on zle vi mode
b133dc92 83function prompt_arrows_keymap_select {
d3712462 84 prompt_arrows_vimode="${KEYMAP:/(main|viins)/}"
1f53b630 85 zle reset-prompt
86}
87
d3712462 88function prompt_arrows_precmd {
1f53b630 89 vcs_info
90}
91
d3712462 92function prompt_arrows_preexec {
f4a5f003 93 print -Pn "%F{red}<<<%f "
94}
95
d3712462 96prompt_arrows_setup "$@"
81c3957e 97# vim: set et fenc=utf-8 ft=zsh sts=4 sw=4 ts=8 tw=0 :
This page took 0.046037 seconds and 4 git commands to generate.