-
Notifications
You must be signed in to change notification settings - Fork 0
/
togglecursor.plugin.zsh
55 lines (46 loc) · 1.25 KB
/
togglecursor.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
#!/usr/bin/env zsh
autoload -U is-at-least
autoload -U add-zle-hook-widget
_zsh_togglecursor() {
local ret=$?
case $KEYMAP in
'main')
_zsh_togglecursor_apply_cursor 'line'
;;
*)
_zsh_togglecursor_apply_cursor 'block'
;;
esac
return $ret
}
_zsh_togglecursor_reset() {
_zsh_togglecursor_apply_cursor 'block'
}
_zsh_togglecursor_supported() {
[[ $TERM_PROGRAM =~ tmux\|iTerm\.app\|Apple_Terminal ]] ||
[[ -n $WT_SESSION ]] ||
[[ $VTE_VERSION -ge 3900 ]] ||
[[ $TERMINAL_EMULATOR = 'JetBrains-JediTerm' ]]
}
_zsh_togglecursor_apply_cursor() {
_zsh_togglecursor_supported || return $ret
local format='%b'
case "$1" in
'block')
printf $format "\e[1 q"
;;
'underline')
printf $format "\e[3 q"
;;
'line')
printf $format "\e[5 q"
;;
esac
}
if is-at-least 5.3; then
add-zle-hook-widget zle-line-init _zsh_togglecursor
add-zle-hook-widget zle-line-finish _zsh_togglecursor_reset
add-zle-hook-widget zle-keymap-select _zsh_togglecursor
else
print -r -- >&2 'zsh-togglecursor: add-zle-hook-widget is not supported on this version of zsh.'
fi