~kota/kota-prompt

38d66ea39603a861524029f733f3e38728538cbf — Dakota Walsh 1 year, 10 months ago f3f622d
add old-style zsh plugin file
1 files changed, 44 insertions(+), 0 deletions(-)

A kota-prompt.zsh
A kota-prompt.zsh => kota-prompt.zsh +44 -0
@@ 0,0 1,44 @@
# Kota's zsh prompt

# Prompt is path, shortened with ~ and turns red on an error exit code.
# Additionally it turns blue when in normal mode.
# Plugin sets vi-mode if not already set.

# To use you must set PROMPT='$(vi_mode_status)'

# updates editor information when the keymap changes
function zle-keymap-select() {
    # update keymap variable for the prompt
    VI_KEYMAP=$KEYMAP
    zle reset-prompt
}

# start every prompt in insert mode
function zle-line-init() {
    zle -K viins
}

zle -N zle-line-init
zle -N zle-keymap-select

# enable vi keymap (just in case lol)
bindkey -v

# reduce esc delay
export KEYTIMEOUT=1

# prompt variables
: "${VI_NORMAL_MODE_INDICATOR="%F{blue}%~ %f"}"
: "${VI_INSERT_MODE_INDICATOR="%(?..%F{red})%~ %f"}"

# enable prompt substition
setopt PROMPT_SUBST

# set the prompt
function vi_mode_status() {
    if [[ "$VI_KEYMAP" == "vicmd" ]]; then
        echo "$VI_NORMAL_MODE_INDICATOR"
    else
        echo "$VI_INSERT_MODE_INDICATOR"
    fi
}