]> git.sev.monster Git - dotfiles.git/blame - base/.zsh/prompt_arrows_setup
remove legacy FreeBSD scripts
[dotfiles.git] / base / .zsh / prompt_arrows_setup
CommitLineData
4f471013 1prompt_arrows_help() {
fab483dd 2 cat << EOF
4f471013 3prompt arrows <right|2line> <normal> <prompt> <ssh> <urgent> <comment> <dir> <unwritable>
fab483dd 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
4f471013 21local prompt_arrows_vimode=
fab483dd 22
4f471013 23function prompt_arrows_setup() {
fab483dd 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`%%"
4f471013 50 local vicol='%F{${${prompt_arrows_vimode:+'"$r"'}:-'"$c"'}}'
fab483dd 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
4f471013 72 add-zsh-hook precmd prompt_arrows_precmd
73 add-zsh-hook preexec prompt_arrows_preexec
fab483dd 74 zle -N zle-line-init
75 zle -A zle-line-init zle-keymap-select
76}
77
78# change color based on zle vi mode
79function zle-line-init {
4f471013 80 prompt_arrows_vimode="${KEYMAP:/(main|viins)/}"
fab483dd 81 zle reset-prompt
82}
83
4f471013 84function prompt_arrows_precmd {
fab483dd 85 # TODO: check if vcs_info is autoloaded
86 vcs_info
87}
88
4f471013 89function prompt_arrows_preexec {
116467fd 90 print -Pn "%F{red}<<<%f "
91}
92
4f471013 93prompt_arrows_setup "$@"
fab483dd 94# vim: set et fenc=utf-8 ft=zsh sts=4 sw=4 ts=8 tw=0 :
This page took 0.041489 seconds and 4 git commands to generate.