-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcreate_tab_completion.py
executable file
·328 lines (308 loc) · 9.39 KB
/
create_tab_completion.py
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
#!/usr/bin/python3
# By Johannes Bechberger, under MIT License
import sys
import os
description = "description" # hacks that allow better editing in IDEs
zsh = "zsh"
flag = "flag"
multiple = "multiple"
section = "section"
default_completion_item = {
multiple: True, # allow multiple applications
description: "", # description of this parameter
flag: True, # is this argument a flag (without any arguments)?
zsh: "" # completion string for zsh or list of possible arguments
}
completion = {
"Information": {
"--help": {
description: "Display the help text",
},
"--verbosity": {
description: "Set the verbosity level",
flag: False,
zsh: list(range(7)),
}
},
"Output modes": {
"--spatial": {
description: "Create 3d stereo with interaural delays"
},
"--stereo": {
description: "Create intensity stereo (default)"
},
"--multi": {
description: "Create multi channel output"
},
"--mono": {
description: "Create mono output"
},
"--set-stereo-level": {
description: "Set maximum channel volume factor (0.9)",
flag: False
},
"--set-stereo-spatial": {
description: "Set maximum interaural delay distance (0.03)",
flag: False
}
},
"Output targets": {
"--output": {
description: "Write final output to the file in netbpm format",
zsh: "_files"
},
"--plot": {
description: "Write final output to the file in wave format",
zsh: "_files"
},
"--mp3": {
description: "Write final output to the file using external lame",
zsh: "_files"
},
"--ogg": {
description: "Write final output to the file using external oggenc",
zsh: "_files"
},
"--quality": {
description: "Quality from 0-low, 1-standard, 2-high, 3-insane",
zsh: [0, 1, 2, 3]
}
},
"Output meta data": {
"--title": {
description: "Set the title tag if this exists in the output",
flag: False
},
"--artist": {
description: "Set the artist tag if this exists in the output",
flag: False
},
"--album": {
description: "Set the album tag if this exists in the output",
flag: False
},
"--comment": {
description: "Set the comment tag if this exists in the output",
flag: False
},
"--category": {
description: "Set the category tag if this exists in the output",
flag: False
},
"--episode": {
description: "Set the episode tag if this exists in the output",
flag: False
},
"--year": {
description: "Set the year tag if this exists in the output",
flag: False
},
"--image": {
description: "Set the image tag if this exists in the output",
flag: False,
zsh: "_files"
}
},
"New segment selection": {
"--voice": {
description: "Start of voice channel segment (default)"
},
"--mix": {
description: "Start pre-mixed channel segment"
},
"--raw": {
description: "Start of raw channel segment"
}
},
"Segment transition": {
"--fade": {
description: "Fading transition over the given number of seconds",
flag: False
},
"--overlap": {
description: "Overlapping transition over the given number of seconds",
flag: False
},
"--parallel": {
description: "Render previous and next segment in parallel"
}
},
"Crosstalk filter": {
"--xgate": {
description: "Enable robust crosstalk gate"
},
"--no-xgate": {
description: "Disable crosstalk gate"
},
"--xfilter": {
description: "Enable experimental crosstalk filter"
},
"--no-xfilter": {
description: "Disable crosstalk filter"
}
},
"Adaptive silence skip": {
"--soft": {
description: "Soft skip silent passages over 0.5s length"
},
"--skip-target": {
description: "Target length fraction for iteration",
flag: False
},
"--skip-level": {
description: "Fraction of maximum level considered silence (0.01)",
flag: False
},
"--skip-order": {
description: "Order of reduction (0-1, default: 0.75)",
flag: False
},
"--no-skip": {
description: "Do not skip any content"
},
"--trim": {
description: "Trim audio from start and end"
},
"--noise": {
description: "Skip all but silence"
}
},
"Leveling, equalizer and normalization": {
"--leveler": {
description: "Enable selective leveler"
},
"--target": {
description: "Set average target L2 energy for leveler (3000)",
flag: False
},
"--level-mode": {
description: "Shall channels be joined for leveling",
zsh: ["single", "stereo", "multi"]
},
"--no-leveler": {
description: "Disable selective leveler"
},
"--factor": {
description: "Multiply channels by the given factor with sigmoid limiter (1.25)",
flag: False
},
"--no-factor": {
description: "Disable channel multiplier"
},
"--eqvoice": {
description: "Attenuate voice frequency bands"
},
"--no-eqvoice": {
description: "Do not attenuate frequency bands"
},
"--analyze": {
description: "Analyze frequency band components"
},
"--normalize": {
description: "Normalize final mix"
},
"--no-normalize": {
description: "Disable final normalization"
},
"--band-pass": {
description: "[l] [h] [t] Bandpass from l to h Hertz, sharpness t Hertz",
flag: False
},
"--low-pass": {
description: "[f] [t] Lowpass below f Hertz, sharpness t Hertz",
flag: False
},
"--highpass": {
description: "[f] [t] Highpass above f Hertz, sharpness t Hertz",
flag: False
}
},
"Import audio": {
"--left": {
description: "Load left channel of wave file (if stereo)",
zsh: "_files"
},
"--right": {
description: "Load right channel of wave file (if stereo)",
zsh: "_files"
},
"--to-mono": {
description: "Load mono-mixdown of wave file (if stereo)",
zsh: "_files"
},
"--ascii": {
description: "[s] [file] Load ascii wave file with sample rate s",
flag: False
}
}
}
def zsh_completion() -> str:
"""
Generate the tab completion for zsh
"""
def process_item(section: str, name: str, item: dict) -> str:
tmp = default_completion_item.copy()
tmp.update(item)
item = tmp
if item[multiple]:
name = "*" + name
item[description] = item[description].replace("[", "<").replace("]", ">")
ret = name + "[" + item[description] + "]"
if not item[flag] or item[zsh]:
ret += ": :"
if item[zsh]:
if isinstance(item[zsh], list):
ret += "(" + " ".join(repr(x) for x in item[zsh]) + ")"
elif isinstance(item[zsh], str):
ret += item[zsh]
else:
print("Error on zsh completion in " + repr(item), file=sys.stderr)
os.error(1)
return repr(ret)
return """
# Completion script for OSPAC (https://github.com/sritterbusch/ospac)
_ospac(){{
local -a opts
opts=(
"*: :_files"
{}
)
_arguments $opts
}}
compdef _ospac ospac=ospac
""".format("\n ".join(process_item(s, n, completion[s][n]) for s in completion for n in completion[s]))
def bash_completion() -> str:
"""
Generate the tab completion for bash
"""
def process_item(section: str, name: str, item: dict) -> str:
return name
return """
# Completion script for OSPAC (https://github.com/sritterbusch/ospac)
_ospac(){{
local opts
opts=(
{}
)
local cur=${{COMP_WORDS[COMP_CWORD]}}
COMPREPLY=( $(compgen -W "${{opts[*]}}" -- $cur) )
}}
complete -F _ospac ospac
""".format("\n ".join(process_item(s, n, completion[s][n]) for s in completion for n in completion[s]))
if __name__ == "__main__":
USAGE = """
Shell completion generator for ospac.
It generates a tab completion file for bash or zsh.
Usage:
{} [zsh|bash] OUTPUT_FILE
""".format(sys.argv[0])
if len(sys.argv) != 3 or sys.argv[1] not in ["zsh", "bash"]:
print(USAGE)
exit()
compl = ""
if sys.argv[1] == "zsh":
compl = zsh_completion()
elif sys.argv[1] == "bash":
compl = bash_completion()
with open(sys.argv[2], "w") as f:
f.write(compl)