Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ Status of every feature shipped. ✅ = implemented, ⬜ = roadmap. Section ancho
- ✅ JSON (default — pipeable to `jq`)
- ✅ `-H` / `--human` table mode (human-readable)
- ✅ `-q` / `--quiet` mode (exit code only)
- ✅ `completions <bash|zsh>` — generate shell completions
- ✅ `completions <bash|zsh|fish>` — generate shell completions

### Quality (v0.4)
- ✅ 60+ tests `node:test` suite ([`test/`](./test/)) running against [`test/draft_content.json`](./test/draft_content.json)
Expand Down Expand Up @@ -576,7 +576,7 @@ $ capcut set-text ./project a1b2c3 "Hey everyone"
Generate shell completions:

```bash
capcut completions <bash|zsh>
capcut completions <bash|zsh|fish>
```

#### Bash
Expand All @@ -591,6 +591,14 @@ capcut completions bash >> ~/.bashrc
mkdir -p ~/.zsh/completions
capcut completions zsh > ~/.zsh/completions/_capcut
```
Ensure `~/.zsh/completions` is in your `fpath` before running `compinit`.

#### Fish

```bash
mkdir -p ~/.config/fish/completions
capcut completions fish > ~/.config/fish/completions/capcut.fish
```

Completes command names and global flags (`--jianying`, `-H`/`--human`, `-q`/`--quiet`, `-v`/`--version`).

Expand Down
9 changes: 8 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,10 @@ compdef _capcut capcut
`;
}

function fishCompletion(): string {
return [...COMMANDS, ...GLOBAL_FLAGS].map((word) => `complete -c capcut -f -a "${word}"`).join("\n");
}

function parseFlags(args: string[]): { positional: string[]; flags: Flags } {
const positional: string[] = [];
const flags: Flags = { human: false, quiet: false, batch: false };
Expand Down Expand Up @@ -2100,8 +2104,11 @@ async function main(): Promise<void> {
case "zsh":
process.stdout.write(zshCompletion());
break;
case "fish":
process.stdout.write(fishCompletion());
break;
default:
die("Usage: capcut completions <bash|zsh>");
die("Usage: capcut completions <bash|zsh|fish>");
}

process.exit(0);
Expand Down
15 changes: 15 additions & 0 deletions test/completions.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,18 @@ describe("capcut completions zsh", () => {
assert.match(r.stdout, /-v/);
});
});

describe("capcut completions fish", () => {
it("prints fish completion script", () => {
const r = spawnCli(["completions", "fish"]);

assert.match(r.stdout, /info/);
assert.match(r.stdout, /tracks/);
assert.match(r.stdout, /--jianying/);
assert.match(r.stdout, /--quiet/);
assert.match(r.stdout, /--version/);
assert.match(r.stdout, /-H/);
assert.match(r.stdout, /-q/);
assert.match(r.stdout, /-v/);
});
});
Loading