Skip to content

Commit

Permalink
Use a bash 4.3-style mode indicator for vi mode
Browse files Browse the repository at this point in the history
  • Loading branch information
agkozak committed May 12, 2018
1 parent 62b2dbd commit 34d9cc5
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions polyglot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,19 @@ if [ -n "$ZSH_VERSION" ]; then
}

###########################################################
# When the user enters vi command mode, the % or # in the
# prompt changes into a colon
# When in vi mode, the prompt will use a bash 4.3-style
# mode indicator at the beginning of the line -- '+' for
# insert mode, ':' for command mode.
###########################################################
_polyglot_zsh_vi_mode_indicator() {
case $KEYMAP in
vicmd) print -n ':' ;;
*) print -n '%#' ;;
case $(bindkey -lL main) in
*viins*)
case $KEYMAP in
vicmd) print -n ':' ;;
*) print -n '+' ;;
esac
;;
*) ;;
esac
}

Expand Down Expand Up @@ -257,9 +263,9 @@ if [ -n "$ZSH_VERSION" ]; then
unset RPS1 # Clean up detritus from previously loaded prompts

if _polyglot_has_colors; then
PS1='%(?..%B%F{red}(%?%)%b%f )%(!.%S.%B%F{green})%n%1v%(!.%s.%f%b) %B%F{blue}%2v%f%b%F{yellow}%3v%f $(_polyglot_zsh_vi_mode_indicator) '
PS1='$(_polyglot_zsh_vi_mode_indicator)%(?..%B%F{red}(%?%)%b%f )%(!.%S.%B%F{green})%n%1v%(!.%s.%f%b) %B%F{blue}%2v%f%b%F{yellow}%3v%f %# '
else
PS1='%(?..(%?%) )%(!.%S.)%n%1v%(!.%s.) %2v%3v $(_polyglot_zsh_vi_mode_indicator) '
PS1='$(_polyglot_zsh_vi_mode_indicator)%(?..(%?%) )%(!.%S.)%n%1v%(!.%s.) %2v%3v $(_polyglot_zsh_vi_mode_indicator) %# '
fi

#####################################################################
Expand Down

0 comments on commit 34d9cc5

Please sign in to comment.