-
Notifications
You must be signed in to change notification settings - Fork 1
/
completion.xyzsh
278 lines (220 loc) · 8.13 KB
/
completion.xyzsh
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
def xyzsh_quote (
| sub -global ' |\\|"|\$|\*|\?|\[|\]|\{|\}|\&|\;|\(|\)|'\' ( | add -number 0 \\ )
)
def xyzsh_dequote (
| sub -global '(?<!\\)\\' ''
)
def program_completion (
export PATH | split : | ary -local dirs
dirs | each (
| if(| rows -2 | = /) ( |print) else ( | add -number -2 / ) | var -local path
sys::ls $path | each (
| var -local program
print "$path$program" | if(| -x) (
program
)
)
)
print "" | var el::non_append_space_characters
)
def file_completion (
ary ARGV -index 0 | var -local inputing
| if(| rows -2..-1 | =~ '[^\\] ') ( print "" | var -local inputing )
if(inputing | index -quiet /) (
sys::dirname $(inputing |chomp| if (|rows -1 | = /) ( |add aaa ) else ( | print ) ) | chomp | if(|rows -1 | = /) ( | print ) ( | add /) | var -local DIR
eval "print $DIR" | xyzsh_dequote| expand_tilda | var -local DIR2
sys::ls -a $DIR2 | egrep -v '^\.$|^\.\.$' | if(uname |= Darwin\n && (export LANG LC_ALL) | index -quiet -ignore-case utf-8) ( | sys::iconv -f UTF-8-MAC -t UTF-8) else ( | print ) | each (
| if (|chomp | add -number 0 $DIR2 | -d) (
|chomp | xyzsh_quote | add -number 0 $DIR | add / | pomch
) else (
|chomp | xyzsh_quote | add -number 0 $DIR | pomch
)
)
print $DIR | length -byte | var rl::omit_head_of_completion_display_matches
) else (
if(inputing | rows 0 | = \~) (
cat /etc/passwd | each (
| split : | ary -local Field
if(ary Field -size | -ge 7) (
print \~
ary Field -index 0 | chomp
print /\n
)
)
) else (
sys::ls -a | egrep -v '^\.$|^\.\.$' | if(uname |= Darwin\n && (export LANG LC_ALL) | index -quiet -ignore-case utf-8) ( | sys::iconv -f UTF-8-MAC -t UTF-8 ) else ( | print ) | each (
| if (|chomp| -d) (
| chomp | xyzsh_quote | add / | pomch
) else (
|chomp| xyzsh_quote | pomch
)
)
)
)
print "/" | var el::non_append_space_characters
)
class object_completion (
ary ARGV -index 0 | var -local Kind
ary ARGV -index 1 | var -local inputing
if(inputing | index -quiet ::) (
inputing | strip | split :: | lines 0..-2 | join :: | var -local PREFIX
if(Kind | = all\n) (
eval "${PREFIX}::show" | each ( | if(|=~ ': object$') (| sub '(.+):' '\1:::' ) else (|print) ) | scan '(.+?:?:?):' | each ( | add -number 0 ${PREFIX}:: )
) else (
eval "${PREFIX}::show" | egrep ": $Kind\$|: object\$" | each ( | if(|=~ ': object$') (| sub '(.+):' '\1:::' ) else (|print) ) | scan '(.+?:?:?):' | each ( | add -number 0 ${PREFIX}:: )
)
) else (
pwo | var -local current
while(true) (
if(Kind | = all\n) (
eval "${current}::show" | each ( | if(|=~ ': object$') (| sub '(.+):' '\1:::' ) else (|print) ) | ::scan '(^.+?:?:?):'
) else (
eval "${current}::show" | egrep ": $Kind\$|: object\$" | each ( | if(|=~ ': object$') (| sub '(.+):' '\1:::' ) else (|print) ) | ::scan '(^.+?:?:?):'
)
if(current | = root\n) ( break )
current | strip | split :: | lines 0..-2| join :: | var -local current
)
)
print ":" | var el::non_append_space_characters
)
root | egrep ': native function$' | egrep -v '^run: native function$|^show: native function$' | scan '(^.+):' | add sub\nsplit\nscan\n | each (
| var -local command
help $command | lines 1..-1 | scan '^-[a-zA-Z0-9-]+' |chomp| add -number 0 $command\a | hash -append -La COMPLETION_OPTIONS
print <<<EOS
completion "$command" (
hash COMPLETION_OPTIONS -key "$command"
)
EOS | eval
)
completion var (
| object_completion var $ARGV[1]
hash COMPLETION_OPTIONS -key var
)
completion ary (
| object_completion array $ARGV[1]
hash COMPLETION_OPTIONS -key ary
)
completion hash (
| object_completion hash $ARGV[1]
hash COMPLETION_OPTIONS -key hash
)
completion class (
| object_completion class $ARGV[1]
hash COMPLETION_OPTIONS -key class
)
completion def (
| object_completion function $ARGV[1]
hash COMPLETION_OPTIONS -key def
)
completion completion (
| object_completion completion $ARGV[1]
hash COMPLETION_OPTIONS -key completion
)
completion alias (
| object_completion alias $ARGV[1]
hash COMPLETION_OPTIONS -key alias
)
completion ref (
| object_completion all $ARGV[1]
hash COMPLETION_OPTIONS -key ref
)
completion defined (
| object_completion all $ARGV[1]
hash COMPLETION_OPTIONS -key defined
)
completion objinfo (
| object_completion all $ARGV[1]
hash COMPLETION_OPTIONS -key defined
)
completion typeof (
| object_completion all $ARGV[1]
hash COMPLETION_OPTIONS -key typeof
)
completion export (
sys::env | scan '(.+?)=' | sys::sort | uniq
)
completion sweep (
self | egrep -v external\ program\$ | egrep -v native\ function\$ | egrep -v '^root:|^self:|^parent:|^run:'| ::scan '(^.+?):'
hash COMPLETION_OPTIONS -key sweep
)
completion help (
::self | egrep native\ function\$ | ::scan '(^.+?):' | add sub\nsplit\nscan\n | each ( | chomp | quote | pomch )
hash COMPLETION_OPTIONS -key help
)
completion write (
hash COMPLETION_OPTIONS -key write
| file_completion $ARGV[1]
)
completion unset (
sys::env | scan '(.+?)='
)
completion load (
| if(| index -quiet "-dynamic-library" ) (
sys::ls $XYZSH_EXT_PATH | (| print -read-from-error; | print) | egrep '.so$|.dll$'
sys::ls ~/.xyzsh/lib | ( | print -read-from-error; | print ) | egrep '.so$|.dll$'
) else (
| file_completion $ARGV[1]
hash COMPLETION_OPTIONS -key load
)
)
completion cd (
| file_completion $ARGV[1] | each ( | =~ '/$' && | print )
print ../\n
hash COMPLETION_OPTIONS -key cd
)
object ::compl::rl
object ::compl::el
completion rl::help (
rl::self | egrep native\ function\$ | egrep -v 'run|show' | ::scan '(^.+?):' | each ( | chomp | quote | pomch )
)
completion el::help (
el::self | egrep native\ function\$ | egrep -v 'run|show' | ::scan '(^.+?):' | each ( | chomp | quote | pomch )
)
object ::compl::curses
completion curses::help (
curses::self | egrep native\ function\$ | egrep -v 'run|show' | ::scan '(^.+?):' | each ( | chomp | quote | pomch )
)
###################################################################################
### external program completoins ##################################################
###################################################################################
object ::compl::sys
completion ./configure (
./configure --help | scan '(--[a-zA-Z0-9-]+)' | sys::sort | uniq
)
completion man sys::man (
program_completion
)
completion sudo sys::sudo (
| scan 'sudo .*' | chomp | split '(?<!\\) +' | wc -l | var -local input_num
| scan 'sudo .*' | chomp | split '(?<!\\) +' | lines 1 | var -local program_name
if(input_num | -eq 2) (
program_completion
) elif(input_num | -ge 3) (
try (
completion sys::$program_name
) catch (
| file_completion $ARGV[1]
)
)
)
completion make sys::make (
print Makefile | -e && cat Makefile | scan '(.+?):' | sys::sort | uniq
)
completion git sys::git (
git | awk '/The most commonly used git commands are:/,p' | lines 1..-2 | scan '^\s+(.+?)\s+' | sys::sort | uniq
)
completion kill sys::kill (
ps uwx | ( | print -read-from-error > /dev/null; | print) | each ( | sub '^\s+' '' ) | selector | split | lines 1
if(uname |= FreeBSD\n) (rl::clear_screen)
)
completion pkill sys::pkill (
ps wx | ( | print -read-from-error > /dev/null; | print) | lines 1..-1 | each ( | strip | split | lines 4 | strip | split / | lines -1 )
)
completion sys::__all__ (
ARGV | var -local Program inputing
| file_completion $ARGV[1]
)
completion __all__ (
ARGV | var -local Program inputing
| file_completion $ARGV[1]
)