generated from spaceship-prompt/spaceship-section
-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathspaceship-vi-mode.plugin.zsh
executable file
·58 lines (48 loc) · 1.78 KB
/
spaceship-vi-mode.plugin.zsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#
# vi-mode
#
# ------------------------------------------------------------------------------
# Configuration
# ------------------------------------------------------------------------------
SPACESHIP_VI_MODE_SHOW="${SPACESHIP_VI_MODE_SHOW=true}"
SPACESHIP_VI_MODE_PREFIX="${SPACESHIP_VI_MODE_PREFIX=""}"
SPACESHIP_VI_MODE_SUFFIX="${SPACESHIP_VI_MODE_SUFFIX="$SPACESHIP_PROMPT_DEFAULT_SUFFIX"}"
SPACESHIP_VI_MODE_INSERT="${SPACESHIP_VI_MODE_INSERT="[I]"}"
SPACESHIP_VI_MODE_NORMAL="${SPACESHIP_VI_MODE_NORMAL="[N]"}"
SPACESHIP_VI_MODE_COLOR="${SPACESHIP_VI_MODE_COLOR="white"}"
# ------------------------------------------------------------------------------
# Section
# ------------------------------------------------------------------------------
# Show current vi-mode mode
spaceship_vi_mode() {
[[ $SPACESHIP_VI_MODE_SHOW == true ]] || return
if bindkey | grep "vi-quoted-insert" > /dev/null 2>&1; then # check if vi-mode enabled
local mode_indicator="${SPACESHIP_VI_MODE_INSERT}"
case "${KEYMAP}" in
main|viins)
mode_indicator="${SPACESHIP_VI_MODE_INSERT}"
;;
vicmd)
mode_indicator="${SPACESHIP_VI_MODE_NORMAL}"
;;
esac
spaceship::section::v3 \
"$SPACESHIP_VI_MODE_COLOR" \
"$SPACESHIP_VI_MODE_PREFIX" \
"$mode_indicator" \
"$SPACESHIP_VI_MODE_SUFFIX"
fi
}
# ------------------------------------------------------------------------------
# Helpers
# ------------------------------------------------------------------------------
# Temporarily switch to vi-mode
spaceship_vi_mode_enable() {
function zle-keymap-select() { spaceship::core::refresh_section "vi_mode" ; zle .reset-prompt && zle -R }
zle -N zle-keymap-select
bindkey -v
}
# Temporarily switch to emacs-mode
spaceship_vi_mode_disable() {
bindkey -e
}