]> git.sev.monster Git - dotfiles.git/blame - etc/zsh/functions/Prompts/prompt_arrows_setup
use xdg for vim config, add viminfo to xdg
[dotfiles.git] / etc / 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() {
7ddca96d 25 prompt_opts=( cr sp percent subst )
26
27
c7e3e126 28 # XXX: no checks for color terminal or if escapes work, except for echotc
7ddca96d 29 local m n p s r c d u
b341b38a 30 #TODO: remove n?
7ddca96d 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
1f53b630 39
40 # [AC]CURSED COMMAND
41 # concatenate the numerical values of each letter of the hostname,
42 # moduloing by the number of possible colors.
c7e3e126 43 x=$(echotc Co)
44 [[ -z $x ]] && x=8
7ddca96d 45 local generated=$(uname -n | od -An -td1 | awk -F' ' \
46 "{for (i=1; i<=NF; i++) {sum+=1; sum*=\$i; sum%=$(echotc Co)} print sum}")
47 [[ $p = random ]] && p=$generated
48 [[ $s = random ]] && s=$generated
1f53b630 49
50 # use ssh color if connected
7ddca96d 51 [[ -v SSH_CLIENT ]] && p=$s
1f53b630 52
53 local clock="%F{$n}%T%f" dirvcs="%F{$d}"'${vcs_info_msg_0_:-%~}'"%f"
73492710 54 # XXX: linux only
1f53b630 55 local battery=/sys/class/power_supply/BAT0/capacity
57948260 56 [[ -e "$battery" ]] && clock+=' $(cat "'"$battery"'")%%'
d3712462 57 local vicol='%F{${${prompt_arrows_vimode:+'"$r"'}:-'"$c"'}}'
73492710 58 local hist="%F{$n}%h"
1f53b630 59 case "$m" {
60 2line)
73492710 61 PROMPT="%f $hist $clock $dirvcs"$'\n'"%F{$c}>>> "
1f53b630 62 unset RPROMPT
63 ;;
64 right)
65 RPROMPT="$dirvcs $clock"
73492710 66 PROMPT="%F{$c}>>> $hist"
1f53b630 67 ;;
68 *)
69 echo "Unknown prompt mode $m"
70 return
71 ;;
72 }
73 PROMPT="$PROMPT%(1j,%F{$c}%j,)$vicol%#%F{$p}%n%F{$n}@%F{$p}%2m%(?..%F{$n}/%F{$r}\$?)%F{$n}: "
7ddca96d 74 POSTEDIT="$(print -P "%F{$n}%f")"
81c3957e 75 autoload -Uz vcs_info
1f53b630 76 zstyle ':vcs_info:git*' formats "%c%u%%F{$p}%r/%b%%F{$n}/%%F{$d}%S%%f"
77 zstyle ':vcs_info:git*' actionformats "%%F{$r}(%a)%f %c%u%%F{$p}%r/%b%f/%%F{$d}%S%f"
78 zstyle ':vcs_info:git*' stagedstr "%F{$c}+"
79 zstyle ':vcs_info:git*' unstagedstr "%F{$r}*"
80
b133dc92 81 # add-zsh-hook should have already been autoloaded by promptinit
d3712462 82 add-zsh-hook precmd prompt_arrows_precmd
b133dc92 83 autoload -Uz add-zle-hook-widget
84 add-zle-hook-widget line-init prompt_arrows_keymap_select
85 add-zle-hook-widget keymap-select prompt_arrows_keymap_select
1f53b630 86}
87
88# change color based on zle vi mode
b133dc92 89function prompt_arrows_keymap_select {
d3712462 90 prompt_arrows_vimode="${KEYMAP:/(main|viins)/}"
1f53b630 91 zle reset-prompt
92}
93
d3712462 94function prompt_arrows_precmd {
1f53b630 95 vcs_info
96}
97
7ddca96d 98function prompt_arrows_preview {
99 if (( ! $#* )); then
100 prompt_preview_theme arrows 2line
101 print '\n'
102 prompt_preview_theme arrows right
103 print
104 else
105 prompt_preview_theme arrows "$@"
106 print
107 fi
108}
109
d3712462 110prompt_arrows_setup "$@"
81c3957e 111# vim: set et fenc=utf-8 ft=zsh sts=4 sw=4 ts=8 tw=0 :
This page took 0.064884 seconds and 4 git commands to generate.