From ff7f19a50b09c06600916ebcffeb99ec339922ae Mon Sep 17 00:00:00 2001 From: AmirSa12 Date: Tue, 7 Oct 2025 10:40:04 +0330 Subject: [PATCH 1/4] mention tab completions --- README.md | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/README.md b/README.md index 4d47f0c..85e5713 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ Elegant CLI Builder - Lazy and Async commands - Pluggable and composable API - Auto generated usage and help +- Shell autocompletion support via [tab](https://github.com/bombshell-dev/tab) integration 🚧 This project is under heavy development. More features are coming soon! @@ -104,6 +105,86 @@ Renders command usage to a string value. Renders usage and prints to the console +## Autocompletions + +Citty integrates seamlessly with [tab](https://github.com/bombshell-dev/tab) to provide shell autocompletions across `zsh`, `bash`, `fish`, and `powershell`. + +```sh +npm install @bomb.sh/tab +``` + +Add autocompletions to your citty CLI: + +```ts +import { defineCommand, createMain } from "citty"; +import tab from "@bomb.sh/tab/citty"; + +const main = defineCommand({ + meta: { + name: "my-cli", + description: "My CLI tool", + }, + subCommands: { + dev: defineCommand({ + meta: { + name: "dev", + description: "Start dev server", + }, + args: { + port: { + type: "string", + description: "Specify port", + }, + host: { + type: "string", + description: "Specify host", + }, + }, + }), + }, +}); + +const completion = await tab(main); + +// Add custom completions for option values +const devCommand = completion.commands.get("dev"); +const portOption = devCommand.options.get("port"); +if (portOption) { + portOption.handler = (complete) => { + complete("3000", "Development port"); + complete("8080", "Production port"); + }; +} + +const cli = createMain(main); +cli(); +``` + +### Testing Completions + +Test your completions locally: + +```sh +node my-cli.js complete -- dev --port= +# Output: --port=3000 Development port +# --port=8080 Production port +``` + +### Installing Completions + +For end users, completions can be installed: + +```sh +# One-time setup (zsh example) +source <(my-cli complete zsh) + +# Permanent setup +my-cli complete zsh > ~/.my-cli-completion.zsh +echo 'source ~/.my-cli-completion.zsh' >> ~/.zshrc +``` + +Learn more about tab at [github.com/bombshell-dev/tab](https://github.com/bombshell-dev/tab). + ## Development - Clone this repository From 2553758d4c2957cde4b7706130499c15d10bd068 Mon Sep 17 00:00:00 2001 From: AmirSa12 Date: Tue, 7 Oct 2025 10:43:34 +0330 Subject: [PATCH 2/4] update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 85e5713..d339d6c 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ Renders usage and prints to the console ## Autocompletions -Citty integrates seamlessly with [tab](https://github.com/bombshell-dev/tab) to provide shell autocompletions across `zsh`, `bash`, `fish`, and `powershell`. +Citty works with [tab](https://github.com/bombshell-dev/tab) to provide shell autocompletions across `zsh`, `bash`, `fish`, and `powershell`. ```sh npm install @bomb.sh/tab From cb22a572e9dd224b994c84799f8a6f972519810a Mon Sep 17 00:00:00 2001 From: AmirSa12 Date: Tue, 7 Oct 2025 11:03:48 +0330 Subject: [PATCH 3/4] pm docs --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index d339d6c..d387e04 100644 --- a/README.md +++ b/README.md @@ -183,6 +183,19 @@ my-cli complete zsh > ~/.my-cli-completion.zsh echo 'source ~/.my-cli-completion.zsh' >> ~/.zshrc ``` +### Package Manager Completions + +When users install tab, they also get autocompletions for package managers! Tab provides completions for `pnpm`, `npm`, `yarn`, and `bun` out of the box: + +```sh +# Install completions for your package manager +npx @bomb.sh/tab pnpm zsh > ~/.pnpm-completion.zsh && echo 'source ~/.pnpm-completion.zsh' >> ~/.zshrc +npx @bomb.sh/tab npm bash > ~/.npm-completion.bash && echo 'source ~/.npm-completion.bash' >> ~/.bashrc +npx @bomb.sh/tab yarn fish > ~/.config/fish/completions/yarn.fish +``` + +This means your users will enjoy autocompletions not only for your citty CLI but also for their everyday package manager commands! + Learn more about tab at [github.com/bombshell-dev/tab](https://github.com/bombshell-dev/tab). ## Development From d75cac2ef1811b63736dc342232827e93c6623ad Mon Sep 17 00:00:00 2001 From: AmirSa12 Date: Thu, 9 Oct 2025 17:07:20 +0330 Subject: [PATCH 4/4] update --- README.md | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/README.md b/README.md index d387e04..73ff589 100644 --- a/README.md +++ b/README.md @@ -185,15 +185,7 @@ echo 'source ~/.my-cli-completion.zsh' >> ~/.zshrc ### Package Manager Completions -When users install tab, they also get autocompletions for package managers! Tab provides completions for `pnpm`, `npm`, `yarn`, and `bun` out of the box: - -```sh -# Install completions for your package manager -npx @bomb.sh/tab pnpm zsh > ~/.pnpm-completion.zsh && echo 'source ~/.pnpm-completion.zsh' >> ~/.zshrc -npx @bomb.sh/tab npm bash > ~/.npm-completion.bash && echo 'source ~/.npm-completion.bash' >> ~/.bashrc -npx @bomb.sh/tab yarn fish > ~/.config/fish/completions/yarn.fish -``` - +When users install tab, they also get autocompletions for package managers! Tab provides completions for `pnpm`, `npm`, `yarn`, and `bun` out of the box. This means your users will enjoy autocompletions not only for your citty CLI but also for their everyday package manager commands! Learn more about tab at [github.com/bombshell-dev/tab](https://github.com/bombshell-dev/tab).