Skip to content

feat(auto-complete): add shell script output command - #168

Draft
AmirSa12 wants to merge 4 commits into
bloomberg:mainfrom
AmirSa12:feat/tab
Draft

feat(auto-complete): add shell script output command#168
AmirSa12 wants to merge 4 commits into
bloomberg:mainfrom
AmirSa12:feat/tab

Conversation

@AmirSa12

@AmirSa12 AmirSa12 commented Jun 18, 2026

Copy link
Copy Markdown

*Issue number of the reported bug or feature request: #137 and #112 *

Describe your changes
adding a script command to @stricli/auto-complete.
The new command prints a shell completion script to stdout instead of installing it directly into a shell configuration file.

Testing performed

simply run node packages/auto-complete/dist/bin/cli.js script --shell zsh --command "my-cli" my-cli
supports zsh, powershell, fish and bash

Additional context
This is intentionally scoped to script generation only. It does not change stricli's completion proposal logic and does not modify @stricli/core and uses @bomb.sh/tab only for shell script generation.

I havent added the install --zsh
let me know what you think @molisani

@AmirSa12
AmirSa12 requested a review from a team as a code owner June 18, 2026 17:05
@AmirSa12 AmirSa12 changed the title add shell script output command feat(auto-complete): add shell script output command Jun 18, 2026
@AmirSa12
AmirSa12 marked this pull request as draft June 18, 2026 17:11
): void {
const completionCommand = flags.command ?? targetCommand;

tabScript(flags.shell, targetCommand, completionCommand);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct me if I'm wrong, but the tab script that this generates still assumes that the executable is <command> complete -- [...inputs]1 right? Stricli apps won't work with that out of the box.

Footnotes

  1. bash script source, https://github.com/bombshell-dev/tab/blob/7f664740573b3500e8e4749d21fa7cfff98dd716/src/bash.ts#L45

@AmirSa12 AmirSa12 Jun 26, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@molisani yes, you are right, it does not make existing stricli apps support tab’s <command> complete -- ... protocol automatically, and I added that logic manually in a demo.

What I'm thinking about is an opt-in helper like runWithAutoComplete(app, argv, context) that would intercept the complete -- , and thats to avoid changing anything inside the core package. and then users would print or source the scripts via npx @stricli/auto-complete script --shell zsh

Conceptually, this is what I am trying to do:

import { proposeCompletions, run, type Application } from "@stricli/core";
import { emitCompletions, ShellCompDirective } from "@bomb.sh/tab";

export async function runWithAutoComplete(app, argv, context) {
  if (argv[0] === "complete" && argv[1] === "--") {
    const proposals = await proposeCompletions(app, argv.slice(2), context);

    emitCompletions(
      proposals.map((p) => ({
        value: p.completion,
        description: p.brief,
      })),
      ShellCompDirective.ShellCompDirectiveNoFileComp,
    );

    return;
  }

  await run(app, argv, context);
}

@molisani molisani Jun 29, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to change or customize the "subcommand" that the tab shell script expects? For example, could it be <command> --complete [...inputs] instead of <command> complete -- [...inputs]?

@AmirSa12 AmirSa12 Jul 3, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@molisani That's actually a solid idea. I'm experimenting this. I'll keep you posted.

@AmirSa12 AmirSa12 Jul 3, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I have experimented this, and we are good with custom entry points.
but, how do you think we should approach this? what's the mental model you have in mind? did you suggest that because having, for example, --complete is not part of the app's public route tree here in this case?
I'm happy to push this forward to the finish line.

Screenshot 2026-07-03 at 5 03 07 PM

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conceptually, I like having the commands be entirely application-defined. That still allows for sharing/reusing individual commands (like the current install/uninstall commands from the @stricli/auto-complete package), but by design they're composed before the application itself is fully composed. As a result, a single command can't read in a whole application as input (without forcing some really awkward patterns).

I have a work-in-progress branch to implement "integrations", which rewrites the --help/--version functionality as standalone units that can be customized. While I'm not planning to support --complete on a first pass, I'm designing the API such that it could be implemented as a follow-up. The branch is public, but it's not quite ready for a public PR and I'm still iterating on a few details with my colleagues. It should be ready soon.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that makes sense, I see the issue with modeling this as a normal command now...

so for now, I can keep this PR focused on script output only, which addresses issue number #112. please let me know your thoughts on that and the new script command. users would print the shell script via npx @stricli/auto-complete script --shell zsh.

On the tab side, I can still make the generated completion entrypoint configurable so that way stricli could choose something like --complete. and once the new API is ready, we can continue working on the autocomplete feature in a separate PR if things go well.

would be happy to know your thoughts. thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants