-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathra_completion_zsh.go
More file actions
36 lines (35 loc) · 1 KB
/
Copy pathra_completion_zsh.go
File metadata and controls
36 lines (35 loc) · 1 KB
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
package ra
// zshCompletionTemplate generates a zsh completion function.
// Uses semicolons and avoids comments so the output works correctly with both
// `eval "$(cmd completion zsh)"` and `eval $(cmd completion zsh)` (unquoted).
const zshCompletionTemplate = `_%s() {
local -a completions;
local directive;
local out;
out=$(%s __complete "${words[@]:1}" 2>/dev/null);
if [ $? -ne 0 ]; then
return;
fi;
directive=$(echo "$out" | tail -n1 | tr -d ':');
local -a lines;
lines=("${(@f)out}");
lines=("${lines[@]:0:$((${#lines[@]}-1))}");
if (( directive & 1 )); then
return;
fi;
for line in "${lines[@]}"; do
if [ -n "$line" ]; then
completions+=("$line");
fi;
done;
local -a compadd_opts;
if (( directive & 2 )); then
compadd_opts+=(-S '');
fi;
compadd "${compadd_opts[@]}" -a completions;
if (( ! (directive & 4) )) && [ ${#completions[@]} -eq 0 ]; then
_files;
fi;
};
compdef _%s %s;
`