aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsrdusr <trevorgray@srdusr.com>2023-06-04 00:14:21 +0200
committersrdusr <trevorgray@srdusr.com>2023-06-04 00:14:21 +0200
commit073645b320f47888700fb3335466603567a6b879 (patch)
tree401e83eac3ca2a1b5e09918b7ad4ca968e9305ba
parentce387ecd93f82daeb4a8cb2012687a80f55e22e9 (diff)
downloaddotfiles-073645b320f47888700fb3335466603567a6b879.tar.gz
dotfiles-073645b320f47888700fb3335466603567a6b879.zip
Make script more POSIX compliant
-rw-r--r--vi-mode.sh46
1 files changed, 16 insertions, 30 deletions
diff --git a/vi-mode.sh b/vi-mode.sh
index a46f042..ae5b132 100644
--- a/vi-mode.sh
+++ b/vi-mode.sh
@@ -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