generated from spaceship-prompt/spaceship-section
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: migrate vi_mode section from core
- Loading branch information
1 parent
3e1e2c2
commit b705eaa
Showing
2 changed files
with
58 additions
and
41 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 \ | ||
"$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() { zle reset-prompt ; zle -R } | ||
zle -N zle-keymap-select | ||
bindkey -v | ||
} | ||
|
||
# Temporarily switch to emacs-mode | ||
spaceship_vi_mode_disable() { | ||
bindkey -e | ||
} |