Skip to content

Conversation

AmirSa12
Copy link

πŸ”— Linked issue

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This PR introduces tab completion functionality for the nuxt cli, improving developer experience by allowing shell(zsh, powershell, fish, bash) autocompletion for commands, options, values, and flags. With this PR, users can navigate available commands, options and values more efficiently and faster with speeding up workflow.

A small video of how this works:

nuxi.mp4

A small documentation of how CLIs can integrate tab ( in this case, I'm using the citty adapter )

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' },
      },
    }),
  },
});

// Initialize tab completions
const completion = await tab(main);

// Add custom completions
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();

Copy link
Contributor

github-actions bot commented Oct 11, 2025

πŸ“¦ Bundle Size Comparison

πŸ“ˆ nuxi

Metric Base Head Diff
Rendered 5079.11 KB 5114.86 KB +35.75 KB (+0.70%)

➑️ nuxt-cli

Metric Base Head Diff
Rendered 108.86 KB 108.86 KB 0.00 KB (0.00%)

➑️ create-nuxt

Metric Base Head Diff
Rendered 2178.73 KB 2178.73 KB 0.00 KB (0.00%)

Copy link

pkg-pr-new bot commented Oct 11, 2025

nuxt-cli-playground

npm i https://pkg.pr.new/create-nuxt@1082
npm i https://pkg.pr.new/nuxi@1082
npm i https://pkg.pr.new/@nuxt/cli@1082

commit: 11dd4bd

Copy link

codspeed-hq bot commented Oct 11, 2025

CodSpeed Performance Report

Merging #1082 will not alter performance

Comparing AmirSa12:feat/tab-completions (11dd4bd) with main (d8e89aa)

Summary

βœ… 2 untouched

@AmirSa12 AmirSa12 force-pushed the feat/tab-completions branch from b48598c to 2e68892 Compare October 13, 2025 08:52
@AmirSa12 AmirSa12 force-pushed the feat/tab-completions branch from 3fab8fe to 911f4b4 Compare October 13, 2025 09:08
@AmirSa12 AmirSa12 marked this pull request as ready for review October 13, 2025 09:17
@AmirSa12 AmirSa12 requested a review from danielroe as a code owner October 13, 2025 09:17
Copy link
Member

@danielroe danielroe left a comment

Choose a reason for hiding this comment

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

this is looking very, very exciting!

Comment on lines +27 to +31
npx nuxi <Tab>
npm exec nuxi <Tab>
pnpm nuxi <Tab>
yarn nuxi <Tab>
bun nuxi <Tab>
Copy link
Member

Choose a reason for hiding this comment

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

we no longer advise running nuxi as a cli but nuxt directly, for example pnpm nuxt dev within a nuxt project. @nuxt/cli is the package most nuxt users have installed, and it works with both the nuxi and nuxt binaries. nuxi is a legacy all-dependencied-inlined version for portability, but we've chosen to use a lighter version without inlined dependencies for smaller installed size, greater security (and to dedupe deps).

Copy link
Author

Choose a reason for hiding this comment

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

Oh, Thanks for the details! I'll handle it!

import type { ArgsDef, CommandDef } from 'citty'
import tab from '@bomb.sh/tab/citty'

export async function initCompletions<T extends ArgsDef = ArgsDef>(command: CommandDef<T>) {
Copy link
Member

Choose a reason for hiding this comment

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

could we split these up into two sets of completions?

create-nuxt will only need the the init completions (yet won't have init as a subcommand).

Copy link
Author

Choose a reason for hiding this comment

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

yeah sure. I'll do it!

Comment on lines +33 to +42
complete('node-server', 'Node.js server')
complete('static', 'Static hosting')
complete('cloudflare-pages', 'Cloudflare Pages')
complete('vercel', 'Vercel')
complete('netlify', 'Netlify')
complete('aws-lambda', 'AWS Lambda')
complete('azure', 'Azure')
complete('firebase', 'Firebase')
complete('deno-deploy', 'Deno Deploy')
complete('bun', 'Bun runtime')
Copy link
Member

Choose a reason for hiding this comment

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

we have a very long list of possible providers here:

https://nitro.build/deploy

I wonder if it's possible to use nitropack at build time to get this list rather than hard code any of them?

Copy link
Author

Choose a reason for hiding this comment

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

hmm.. are there any approaches you prefer? I thought of fetching from the url (https://nitro.build/deploy) and extracting the names of the providers, but the CLI preset names don't always match the provider names directly. for example, the docs page says β€œCloudflare” but the actual valid presets are: "cloudflare-pages" and "cloudflare-workers" (not just cloudflare)

Copy link
Author

Choose a reason for hiding this comment

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

It would be great if there is a json or a file where we can get the full internal preset keys

Copy link
Member

Choose a reason for hiding this comment

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

I think we can import from nitropack directly

Comment on lines +52 to +53
complete('v3', 'Nuxt 3 template')
complete('v4', 'Nuxt 4 template')
Copy link
Member

Choose a reason for hiding this comment

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

our first-party templates are available at https://github.com/nuxt/starter/tree/templates/templates.

again, do you think maybe we could grab data from these at build-time?

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.

3 participants