dotfiles

$HOME is where the <3 is
git clone git://git.alexkarle.com/dotfiles.git
Log | Files | Refs | Submodules | README

commit 4e5c4e88addd2d2f44bb0b9be966b4369e0b5d38 (patch)
parent 3c141ff5ce331c04a5ffc7d843f6afba30c28cc8
Author: Alexander Karle <akarle@umass.edu>
Date:   Tue, 15 May 2018 21:09:57 -0400

First Zsh Script! Vi Prompt Append!

Diffstat:
Azsh/vi_prompt_append.zsh | 37+++++++++++++++++++++++++++++++++++++
Mzshrc | 13++-----------
2 files changed, 39 insertions(+), 11 deletions(-)

diff --git a/zsh/vi_prompt_append.zsh b/zsh/vi_prompt_append.zsh @@ -0,0 +1,37 @@ +# Vi Prompt Append! +# +# I like Vi(m) related things! I like Vi in my zsh, BUT, not knowing +# which mode (Normal/Insert) you are in can be damaging. SO, I created +# this little script to append an indicator (and change it) for any +# zsh theme! +# +# Assumes bindkey -v is on! +# +# USAGE: +# Source AFTER your theme! (so prompt isn't reset!) + +# First, the globals +VI_NORMAL_PROMPT="%{$fg_bold[yellow]%}[% N]% %{$reset_color%}" +VI_INSERT_PROMPT="%{$fg_bold[blue]%}[% I]% %{$reset_color%}" +VI_PROMPT_CHAR="$VI_INSERT_PROMPT" + +# Simple function to output the Vi prompt +vi_mode() { + local vi_mode_chars="${VI_PROMPT_CHAR}" + echo -n "$vi_mode_chars" +} + +# The magic is here -- append to PROMPT +# Note to self -- need '' around the vi_mode function +PROMPT='$(vi_mode)'"$PROMPT" + +# This function changes the prompt / resets it on Normal/Insert toggle +# Heavily inspired by Doug Black (https://dougblack.io/words/zsh-vi-mode.html) +function zle-line-init zle-keymap-select { + # for use in my custom vi prompt append + VI_PROMPT_CHAR="${${KEYMAP/vicmd/$VI_NORMAL_PROMPT}/(main|viins)/$VI_INSERT_PROMPT}" + zle reset-prompt +} + +zle -N zle-line-init +zle -N zle-keymap-select diff --git a/zshrc b/zshrc @@ -9,7 +9,6 @@ ZSH_THEME="refined" plugins=(git zsh-syntax-highlighting docker) source $ZSH/oh-my-zsh.sh -REFINED_PROMPT="$PROMPT" # store the prompt (we append to it for insert/normal mode!) export DEFAULT_USER="$(whoami)" @@ -23,7 +22,6 @@ export EDITOR="vim" KEYTIMEOUT=1 # vi keymap in terminal -# credit: Doug Black (https://dougblack.io/words/zsh-vi-mode.html) bindkey -v # backspace works past insert mode location @@ -32,15 +30,8 @@ bindkey '^?' backward-delete-char # ctrl-r starts searching history backward bindkey '^r' history-incremental-search-backward -function zle-line-init zle-keymap-select { - VIM_NORMAL_PROMPT="%{$fg_bold[yellow]%}[% N]% %{$reset_color%}" - VIM_INSERT_PROMPT="%{$fg_bold[blue]%}[% I]% %{$reset_color%}" - PS1="${${KEYMAP/vicmd/$VIM_NORMAL_PROMPT}/(main|viins)/$VIM_INSERT_PROMPT} $REFINED_PROMPT" - zle reset-prompt -} - -zle -N zle-line-init -zle -N zle-keymap-select +# Indicate vi mode! +source ~/.akarledots/zsh/vi_prompt_append.zsh # alias for homebrew versions of things # alias ctags='/usr/local/Cellar/ctags/5.8_1/bin/ctags'