Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(completions): Offer Nushell completions #6366

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Kissaki
Copy link
Contributor

@Kissaki Kissaki commented Nov 2, 2024

Clap offers Nushell completions in a crate clap_complete_nushell separate from the crate clap_complete.

clap_complete::Shell and clap_complete_nushell::Nushell share the clap_complete::Generator trait.

I'm not too familiar with Rust, and all attempts to use a more direct match to common trait and call generate in one place only failed.

  1. Introduce enum CompletionShell to unify the options for our command line across these
  2. On command, match CompletionShell to their respective counterparts and call generate with them

The completions can be used in Nushell with:

mkdir $nu.cache-dir
starship completions nushell | save -f $'($nu.cache-dir)/starship-completions.nu'
use $'($nu.cache-dir)/starship-completions.nu' *

and can be set up in the env.nu and config.nu for automatic loading respectively.


Motivation and Context

Nushell can offer extensive, typed command completion, including external commands.

Starship already offers completions generation through the completions command, implemented through the clap library. The clap library also natively, but as a separate crate, offers to generate Nushell completions.

Screenshots (if appropriate):

How Has This Been Tested?

  • I have tested using MacOS
  • I have tested using Linux
  • I have tested using Windows
    • Local cargo build, nutshell commands as described above, and checking that the Nushell completions show up as expected
    • starship completions -h
    • starship completions nushell
    • starship completions bash
    • starship completions fish

Checklist:

  • I have updated the documentation accordingly. - I don't see any docs about completions
  • I have updated the tests accordingly. - I don't see any tests about completions

Clap offers Nushell completions in a crate clap_complete_nushell separate from the crate clap_complete.

clap_complete::Shell and clap_complete_nushell::Nushell share the clap_complete::Generator trait.

I'm not too familiar with Rust, and all attempts to use a more direct match to common trait and call generate in one place only failed.

1. Introduce enum `CompletionShell` to unify the options for our command line across these
2. On command, match CompletionShell to their respective counterparts and call generate with them

---

The completions can be used in Nushell with:

```nu
mkdir $nu.cache-dir
starship completions nushell | save -f $'($nu.cache-dir)/starship-completions.nu'
use $'($nu.cache-dir)/starship-completions.nu' *
```

and can be set up in the env.nu and config.nu for automatic loading respectively.
Corrects display order in command help shell list
Kissaki added a commit to Kissaki/nushell-config that referenced this pull request Nov 15, 2024
Open PR, starship/starship#6366, no response/feedback for two weeks yet
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.

1 participant