diff options
| author | srdusr <trevorgray@srdusr.com> | 2023-04-04 04:56:30 +0200 |
|---|---|---|
| committer | srdusr <trevorgray@srdusr.com> | 2023-04-04 04:56:30 +0200 |
| commit | dc19e6210735217d9659d2c0a6034ce0ce82bc86 (patch) | |
| tree | 04e50256432af020f8ec5b55f034d4d4c02ddfc7 | |
| parent | cbc41ba76c0da3489b6162f52bc37a7225e97364 (diff) | |
| download | dotfiles-dc19e6210735217d9659d2c0a6034ce0ce82bc86.tar.gz dotfiles-dc19e6210735217d9659d2c0a6034ce0ce82bc86.zip | |
Better prompt (new line) for zsh
| -rw-r--r-- | vi-mode.sh | 40 |
1 files changed, 31 insertions, 9 deletions
@@ -6,16 +6,38 @@ if [[ -n "$ZSH_VERSION" ]]; then export KEYTIMEOUT=1 # Show which mode - function zle-keymap-select { - if [[ $KEYMAP == vicmd ]] || - [[ $1 = 'block' ]]; then - echo -n -- NORMAL -- - else - echo -n -- INSERT -- - fi - echo -ne '\n' - zle reset-prompt + terminfo_down_sc=$terminfo[cud1]$terminfo[cuu1]$terminfo[sc]$terminfo[cud1] + + function insert-mode () { echo "-- INSERT --" } + function normal-mode () { echo "-- NORMAL --" } + + precmd () { + # yes, I actually like to have a new line, then some stuff and then + # the input line + print -rP " + [%D{%a, %d %b %Y, %H:%M:%S}] %n %{$fg[blue]%}%m%{$reset_color%}" + + # this is required for initial prompt and a problem I had with Ctrl+C or + # Enter when in normal mode (a new line would come up in insert mode, + # but normal mode would be indicated) + PS1="%{$terminfo_down_sc$(insert-mode)$terminfo[rc]%}%~ $ " } + function set-prompt () { + case ${KEYMAP} in + (vicmd) VI_MODE="$(normal-mode)" ;; + (main|viins) VI_MODE="$(insert-mode)" ;; + (*) VI_MODE="$(insert-mode)" ;; + esac + PS1="%{$terminfo_down_sc$VI_MODE$terminfo[rc]%}%~ $ " + } + + function zle-line-init zle-keymap-select { + set-prompt + zle reset-prompt + } + preexec () { print -rn -- $terminfo[el]; } + + zle -N zle-line-init zle -N zle-keymap-select # Fix backspace bug when switching modes |
