-
-
Notifications
You must be signed in to change notification settings - Fork 64
/
zsh.ts
28 lines (25 loc) 路 899 Bytes
/
zsh.ts
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
import { Command } from "../command.ts";
import { dim, italic } from "../deps.ts";
import { ZshCompletionsGenerator } from "./_zsh_completions_generator.ts";
/** Generates zsh completions script. */
export class ZshCompletionsCommand extends Command<void> {
#cmd?: Command;
public constructor(cmd?: Command) {
super();
this.#cmd = cmd;
this.description(() => {
const baseCmd = this.#cmd || this.getMainCommand();
return `Generate shell completions for zsh.
To enable zsh completions for this program add following line to your ${
dim(italic("~/.zshrc"))
}:
${dim(italic(`source <(${baseCmd.getPath()} completions zsh)`))}`;
})
.action(() => {
const baseCmd = this.#cmd || this.getMainCommand();
Deno.stdout.writeSync(new TextEncoder().encode(
ZshCompletionsGenerator.generate(baseCmd),
));
});
}
}