-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautoc.zsh
executable file
·114 lines (99 loc) · 2.07 KB
/
autoc.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# zsh-shell-autocomplete for vscode
# GitHub : https://github.com/onvno/zsh-shell-autocomplete
# Email : [email protected]
# Author : onvno
autoload -U compinit
zle -N self-insert self-insert-incr
zle -N backward-delete-char-incr
compinit
bindkey -M emacs '^h' backward-delete-char-incr
bindkey -M emacs '^?' backward-delete-char-incr
unsetopt automenu
compdef -d scp
compdef -d tar
compdef -d make
compdef -d java
compdef -d svn
compdef -d cvs
# TODO:
# cp dir/
now_predict=0
function limit-completion
{
if ((compstate[nmatches] <= 1)); then
zle -M ""
elif ((compstate[list_lines] > 50)); then
compstate[list]=""
zle -M "too many matches."
fi
}
function correct-prediction
{
if ((now_predict == 1)); then
if [[ "$BUFFER" != "$buffer_prd" ]] || ((CURSOR != cursor_org)); then
now_predict=0
fi
fi
}
function remove-prediction
{
if ((now_predict == 1)); then
BUFFER="$buffer_org"
now_predict=0
fi
}
function show-prediction
{
# assert(now_predict == 0)
if
((PENDING == 0)) &&
((CURSOR > 1)) &&
[[ "$PREBUFFER" == "" ]] &&
[[ "$BUFFER[CURSOR]" != " " ]]
then
cursor_org="$CURSOR"
buffer_org="$BUFFER"
comppostfuncs=(limit-completion)
zle complete-word
cursor_prd="$CURSOR"
buffer_prd="$BUFFER"
if [[ "$buffer_org[1,cursor_org]" == "$buffer_prd[1,cursor_org]" ]]; then
CURSOR="$cursor_org"
if [[ "$buffer_org" != "$buffer_prd" ]] || ((cursor_org != cursor_prd)); then
now_predict=1
fi
else
BUFFER="$buffer_org"
CURSOR="$cursor_org"
fi
echo -n "\e[32m"
else
zle -M ""
fi
}
function preexec
{
echo -n "\e[39m"
}
function self-insert-incr
{
correct-prediction
remove-prediction
if { zle .self-insert } {
if [[ "${BUFFER:0:3}" == "cd " ]] || [[ "${BUFFER:0:4}" == "cat " ]] || [[ "${BUFFER:0:5}" == "code " ]] {
show-prediction
}
}
}
function backward-delete-char-incr
{
correct-prediction
remove-prediction
if { zle backward-delete-char } {
if [[ "${BUFFER:0:3}" == "cd " ]] || [[ "${BUFFER:0:4}" == "cat " ]] || [[ "${BUFFER:0:5}" == "code " ]] {
show-prediction
} else {
remove-prediction
}
}
}