zsh: add support for iTerm when changing cursor shape
This commit is contained in:
parent
04e132288c
commit
7a01021042
3 changed files with 37 additions and 12 deletions
|
@ -243,5 +243,6 @@ deploy_zsh() {
|
|||
link "$DOTFILES/zsh/aliases" "$ZDOTDIR/aliases"
|
||||
link "$DOTFILES/zsh/prompt" "$ZDOTDIR/prompt"
|
||||
link "$DOTFILES/zsh/solarized" "$ZDOTDIR/solarized"
|
||||
link "$DOTFILES/zsh/vi-mode" "$ZDOTDIR/vi-mode"
|
||||
}
|
||||
|
||||
|
|
35
zsh/vi-mode
Normal file
35
zsh/vi-mode
Normal file
|
@ -0,0 +1,35 @@
|
|||
#!/bin/zsh
|
||||
|
||||
# Use vi mode for line editing.
|
||||
bindkey -v
|
||||
export KEYTIMEOUT=1
|
||||
|
||||
set_cursor_shape() {
|
||||
if [ -n ITERM_SESSION_ID ]; then
|
||||
local block='\e]1337;CursorShape=0\a'
|
||||
local bar='\e]1337;CursorShape=1\a'
|
||||
local underline='\e]1337;CursorShape=2\a'
|
||||
else
|
||||
local block='\e[1 q' beam='\e[3 q' underline='\e[5 q'
|
||||
fi
|
||||
|
||||
case "$1" in
|
||||
block) echo -ne "$block" ;;
|
||||
bar) echo -ne "$bar" ;;
|
||||
underline) echo -ne "$underline" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Switch cursor shape depending on editing mode.
|
||||
zle-keymap-select() {
|
||||
case $KEYMAP in
|
||||
vicmd) set_cursor_shape block ;;
|
||||
viins|main) set_cursor_shape bar ;;
|
||||
esac
|
||||
}
|
||||
zle -N zle-keymap-select
|
||||
|
||||
# Start new prompts with bar shaped cursor.
|
||||
zle-line-init() { set_cursor_shape bar; }
|
||||
zle -N zle-line-init
|
||||
|
13
zsh/zshrc
13
zsh/zshrc
|
@ -6,6 +6,7 @@ while read -r f; do [ -f "$f" ] && source "$f"; done <<EOL
|
|||
$ZDOTDIR/aliases
|
||||
$ZDOTDIR/prompt
|
||||
$ZDOTDIR/solarized
|
||||
$ZDOTDIR/vi-mode
|
||||
EOL
|
||||
unset f
|
||||
|
||||
|
@ -17,20 +18,8 @@ HISTFILE="${XDG_DATA_HOME:-$HOME/.local/share}/zsh/history"
|
|||
HISTSIZE=1000000
|
||||
SAVEHIST=1000000
|
||||
|
||||
# Use vi mode for line editing.
|
||||
bindkey -v
|
||||
|
||||
# Use beam cursor on each new prompt
|
||||
precmd() { echo -ne '\e[5 q'; }
|
||||
|
||||
# Switch cursor shape depending on editing mode.
|
||||
zle-keymap-select() {
|
||||
case $KEYMAP in
|
||||
vicmd) echo -ne '\e[1 q';; # block cursor for command mode
|
||||
viins|main) echo -ne '\e[5 q';; # beam cursor for insert mode
|
||||
esac
|
||||
}
|
||||
zle -N zle-keymap-select
|
||||
|
||||
#autoload -U compinit
|
||||
zstyle ':completion:*' menu select
|
||||
|
|
Loading…
Add table
Reference in a new issue