-
Notifications
You must be signed in to change notification settings - Fork 0
/
bindings.zsh
91 lines (82 loc) · 2.62 KB
/
bindings.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
() {
zmodload zsh/terminfo
autoload -Uz add-zle-hook-widget
function expand-or-complete-with-dots() {
emulate -L zsh
local c=$(( ${+terminfo[rmam]} && ${+terminfo[smam]} ))
(( c )) && echoti rmam
print -Pn "%{%F{red}…%f%}"
(( c )) && echoti smam
zle expand-or-complete
zle redisplay
}
local which
for which in up back forward; do
eval "function dirhistory-$which() {
emulate -L zsh
dirhistory_$which
powerlevel9k_refresh_prompt_inplace
zle .reset-prompt && zle -R
}"
done
autoload -U up-line-or-beginning-search down-line-or-beginning-search
zle -N up-line-or-beginning-search
zle -N down-line-or-beginning-search
zle -N expand-or-complete-with-dots
zmodload zsh/terminfo
if (( $+terminfo[smkx] && $+terminfo[rmkx] )); then
function enable-term-application-mode() { echoti smkx }
function disable-term-application-mode() { echoti rmkx }
zle -N enable-term-application-mode
zle -N disable-term-application-mode
add-zle-hook-widget line-init enable-term-application-mode
add-zle-hook-widget line-finish disable-term-application-mode
fi
# Note: You can specify several codes separated by space. All of them will be bound.
#
# For example:
#
# CtrlUp '\e[1;5A \e[A'
#
# Now, any widget in `bindings` that binds to CtrlUp will be bound to '\e[1;5A' and '\e[A'.
local -A key_code=(
Ctrl '^'
Tab '\t'
Backspace '^?'
Delete '\e[3~'
Up "$terminfo[kcuu1]"
Left "$terminfo[kcub1]"
Down "$terminfo[kcud1]"
Right "$terminfo[kcuf1]"
ShiftTab "$terminfo[kcbt]"
CMDLeft '^X\x7f'
CMDShiftZ '^X^_'
)
local -a bindings=(
Up up-line-or-beginning-search # prev command in history
Down down-line-or-beginning-search # next command in history
ShiftTab reverse-menu-complete # previous in completion menu
Tab expand-or-complete-with-dots # show '...' while completing
CMDLeft backward-kill-line # delete all to the left
CMDShiftZ redo
)
local key widget
for key widget in $bindings[@]; do
local -a code=('')
local part=''
for part in ${(@ps:-:)key}; do
if [[ $#part == 1 ]]; then
code=${^code}${(L)part}
elif [[ -n $key_code[$part] ]]; then
local -a p=(${(@ps: :)key_code[$part]})
code=(${^code}${^p})
else
(( $+key_code[$part] )) || echo -E "[ERROR] undefined key: $part" >&2
code=()
break
fi
done
local c=''
for c in $code[@]; do bindkey $c $widget; done
done
}