dotfiles

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

vi_prompt_append.zsh (1170B) [raw]


      1 # Vi Prompt Append!
      2 #
      3 # I like Vi(m) related things! I like Vi in my zsh, BUT, not knowing
      4 # which mode (Normal/Insert) you are in can be damaging. SO, I created
      5 # this little script to append an indicator (and change it) for any
      6 # zsh theme!
      7 #
      8 # Assumes bindkey -v is on!
      9 #
     10 # USAGE:
     11 # Source AFTER your theme! (so prompt isn't reset!)
     12 
     13 # First, the globals
     14 VI_NORMAL_PROMPT="%{$fg_bold[yellow]%}[% N]%  %{$reset_color%}"
     15 VI_INSERT_PROMPT="%{$fg_bold[blue]%}[% I]%  %{$reset_color%}"
     16 VI_PROMPT_CHAR="$VI_INSERT_PROMPT"
     17 
     18 # Simple function to output the Vi prompt
     19 vi_mode() {
     20     local vi_mode_chars="${VI_PROMPT_CHAR}"
     21     echo -n "$vi_mode_chars"
     22 }
     23 
     24 # The magic is here -- append to PROMPT
     25 # Note to self -- need '' around the vi_mode function
     26 PROMPT='$(vi_mode)'"$PROMPT"
     27 
     28 # This function changes the prompt / resets it on Normal/Insert toggle
     29 # Heavily inspired by Doug Black (https://dougblack.io/words/zsh-vi-mode.html)
     30 function zle-line-init zle-keymap-select {
     31     # for use in my custom vi prompt append
     32     VI_PROMPT_CHAR="${${KEYMAP/vicmd/$VI_NORMAL_PROMPT}/(main|viins)/$VI_INSERT_PROMPT}"
     33     zle reset-prompt
     34 }
     35 
     36 zle -N zle-line-init
     37 zle -N zle-keymap-select