diff options
Diffstat (limited to 'vi-mode.sh')
| -rw-r--r-- | vi-mode.sh | 46 |
1 files changed, 16 insertions, 30 deletions
@@ -1,37 +1,37 @@ -#!/bin/bash +#!/bin/sh # Set vi-mode and key bindings for zsh -if [[ -n "$ZSH_VERSION" ]]; then +if [ -n "$ZSH_VERSION" ]; then bindkey -v export KEYTIMEOUT=1 # Show which mode - terminfo_down_sc=$terminfo[cud1]$terminfo[cuu1]$terminfo[sc]$terminfo[cud1] + terminfo_down_sc=$(tput cud1)$(tput cuu1)$(tput sc)$(tput cud1) - function insert-mode () { echo "-- INSERT --" } - function normal-mode () { echo "-- NORMAL --" } + insert-mode () { echo "-- INSERT --"; } + 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%}" + [%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]%}%~ $ " + 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)" ;; + 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]%}%~ $ " + PS1="%{${terminfo_down_sc}${VI_MODE}${terminfo[rc]}%}%~ $ " } - function zle-line-init () { + zle-line-init () { set-prompt zle reset-prompt zle-keymap-select @@ -57,13 +57,13 @@ if [[ -n "$ZSH_VERSION" ]]; then # Map 'jk' to Escape key in INSERT mode bindkey -M viins 'jk' vi-cmd-mode -elif [[ -n "$BASH_VERSION" ]]; then +elif [ -n "$BASH_VERSION" ]; then # Set vi-mode and key bindings for bash set -o vi # Show which mode show-mode() { - if [[ "$BASH_MODE" == "vi" ]]; then + if [ "$BASH_MODE" = "vi" ]; then echo -ne "\[\033[1m\]-- NORMAL --\[\033[0m\]\n" else echo -ne "\[\033[1m\]-- INSERT --\[\033[0m\]\n" @@ -98,17 +98,3 @@ elif [[ -n "$BASH_VERSION" ]]; then else echo "Unsupported shell" fi - -## Reload .bashrc or .bash_profile file if using bash -#if [[ -n "$BASH_VERSION" ]]; then -# if [[ -f "$HOME/.bashrc" ]]; then -# source ~/.bashrc -# elif [[ -f "$HOME/.bash_profile" ]]; then -# source ~/.bash_profile -# fi -#fi -# -## Reload .zshrc file if using zsh -#if [[ -n "$ZSH_VERSION" ]]; then -# source ~/.zshrc -#fi |
