-
Notifications
You must be signed in to change notification settings - Fork 0
/
wsdquit.zsh
51 lines (46 loc) · 1.07 KB
/
wsdquit.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
bindkey -N wsdquit
wsdquit-restore() {
CURSOR=$wsdquit_saved_curs
BUFFER[$wsdquit_saved_length+1,${#BUFFER}]=""
}
wsdquit-undef() {
unset wsdquit_saved_curs
unset wsdquit_saved_length
unset wsdquit_yes
unset wsdquit_no
}
zle -N wsdquit-yes
bindkey -M wsdquit "Y" wsdquit-yes
bindkey -M wsdquit "y" wsdquit-yes
wsdquit-yes() {
wsdquit-restore
zle -K $wsdquit_saved_keymap
if [[ -n "$wsdquit_yes" ]]; then
$wsdquit_yes
fi
wsdquit-undef
}
zle -N wsdquit-no
bindkey -M wsdquit "N" wsdquit-no
bindkey -M wsdquit "n" wsdquit-no
wsdquit-no() {
wsdquit-restore
zle -K $wsdquit_saved_keymap
if [[ -n "$wsdquit_no" ]]; then
$wsdquit_no
fi
wsdquit-undef
}
# prints quit dialog, asks for confirmation, returns true or false
wsdquit-run() {
wsdquit_saved_curs=$CURSOR
local length=${#BUFFER}
wsdquit_saved_length=$length
wsdquit_yes="$1"
wsdquit_no="$2"
local l1="$3"
local l3="$4"
wsdquit_saved_keymap=$KEYMAP
ws-insert-formatted-at $length $'\n'"$l1"$'\n'$'\n'"$l3"
zle -K wsdquit
}