#!/bin/zsh prompt_arrows_help() { cat << EOF prompt arrows The first parameter determines whether or not to use right-aligned status text, or to put it above the command line. All other parameters are Zsh PROMPT_SUBST color values wrapped in '%F{}'. If 'prompt' or 'ssh' are 'random', their respective value will be procedurally generated using the machine hostname as a seed; if the machine is connected to SSH, the 'prompt' value will be replaced with the 'ssh' value. Defaults are white, green, random, red, blue, yellow, and darkyellow respectively. EOF } local prompt_arrows_vimode= function prompt_arrows_setup() { prompt_opts=( cr sp percent subst ) # XXX: no checks for color terminal or if escapes work, except for echotc local m n p s r c d u #TODO: remove n? m=${1:-2line} # Mode n=${2:-white} # Normal p=${3:-green} # Prompt s=${4:-random} # Ssh prompt r=${5:-red} # uRgent c=${6:-blue} # Comment d=${7:-yellow} # Dir u=${8:-darkyellow} # Unwritable # [AC]CURSED COMMAND # concatenate the numerical values of each letter of the hostname, # moduloing by the number of possible colors. x=$(echotc Co) [[ -z $x ]] && x=8 local generated=$(uname -n | od -An -td1 | awk -F' ' \ "{for (i=1; i<=NF; i++) {sum+=1; sum*=\$i; sum%=$(echotc Co)} print sum}") [[ $p = random ]] && p=$generated [[ $s = random ]] && s=$generated # use ssh color if connected [[ -v SSH_CLIENT ]] && p=$s local clock="%F{$n}%T%f" dirvcs="%F{$d}"'${vcs_info_msg_0_:-%~}'"%f" # XXX: linux only local battery=/sys/class/power_supply/BAT0/capacity [[ -e "$battery" ]] && clock+=' $(cat "'"$battery"'")%%' local vicol='%F{${${prompt_arrows_vimode:+'"$r"'}:-'"$c"'}}' local hist="%F{$n}%h" case "$m" { 2line) PROMPT="%f $hist $clock $dirvcs"$'\n'"%F{$c}>>> " unset RPROMPT ;; right) RPROMPT="$dirvcs $clock" PROMPT="%F{$c}>>> $hist" ;; *) echo "Unknown prompt mode $m" return ;; } PROMPT="$PROMPT%(1j,%F{$c}%j,)$vicol%#%F{$p}%n%F{$n}@%F{$p}%2m%(?..%F{$n}/%F{$r}%?)%F{$n}: " POSTEDIT="$(print -P "%F{$n}%f")" autoload -Uz vcs_info zstyle ':vcs_info:git*' get-revision true local gitformat="%c%u%F{$p}%r%F{$n} %F{$c}%7.7i%F{$n}:%F{$p}%b%F{$n} %F{$d}%S%f" zstyle ':vcs_info:git*' formats $gitformat zstyle ':vcs_info:git*' get-unapplied true local patchformat=' %n/%a' zstyle ':vcs_info:git*' patch-format $patchformat zstyle ':vcs_info:git*' nopatch-format $patchformat zstyle ':vcs_info:git*+post-backend:*' hooks prompt_arrows_revertfix zstyle ':vcs_info:git*' actionformats "%F{$r}(%a%m)%f $gitformat" zstyle ':vcs_info:git*' stagedstr "%F{$c}+" zstyle ':vcs_info:git*' unstagedstr "%F{$r}!" # add-zsh-hook should have already been autoloaded by promptinit add-zsh-hook precmd prompt_arrows_precmd autoload -Uz add-zle-hook-widget add-zle-hook-widget line-init prompt_arrows_keymap_select add-zle-hook-widget keymap-select prompt_arrows_keymap_select } # change color based on zle vi mode function prompt_arrows_keymap_select { prompt_arrows_vimode="${KEYMAP:/(main|viins)/}" zle reset-prompt } function prompt_arrows_precmd { vcs_info } function prompt_arrows_preview { if (( ! $#* )); then prompt_preview_theme arrows 2line print '\n' prompt_preview_theme arrows right print else prompt_preview_theme arrows "$@" print fi } function +vi-prompt_arrows_revertfix() { [[ -f "$gitdir/REVERT_HEAD" ]] && hook_com[action]=revert } prompt_arrows_setup "$@"