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