nushell / nushell

A new type of shell
https://www.nushell.sh/
MIT License
31.01k stars 1.59k forks source link

Parse arguments from manpages for completions #6075

Open poperigby opened 1 year ago

poperigby commented 1 year ago

Describe the solution you'd like

Fish does something very cool where it parses man pages to generate completions for programs. Would this be something usefull for nushell, so it doesn't entirely rely on manually created completions?

Here's their implementation: https://github.com/fish-shell/fish-shell/blob/master/share/tools/create_manpage_completions.py

Describe alternatives you've considered

There's already a small repository of completions in nu_scripts, and this is probably preferred, but these could never possibly cover all of the niche programs out there. Fish also has a repository of manually created completions for a lot of programs, and the man page parsing is used as a fallback, I believe.

vyvl commented 1 year ago

There is a script to parse fish completions generated from parsing man pages : https://github.com/nushell/nu_scripts/blob/main/custom-completions/auto-generate/parse-fish.nu . I also prefer nu to automatically parse man pages after installation and generate completions but not sure if that works cross platform.

fdncred commented 1 year ago

Parsing the troff files is non-trivial. I have looked into doing this myself. Even if you just port that script from python to nushell, I bet it won't be easy.

Having said that, I LOVE to see a nushell port of that script. I also agree that we'd still want to store the completions since man pages don't really exist on Windows but some of the commands can be installed and used on Windows.

poperigby commented 1 year ago

What do you think would be difficult about porting the script?

fdncred commented 1 year ago

Mostly my personal ignorance of python. Have at it! I wish you success. :)

I mean, it is a script with over 1000 lines so just the volume of it makes it non-trivial.

adhadse commented 1 year ago

If anyone coming here to check for external commands autocompletion, nushell supports external completers and checkout carapace

sholderbach commented 1 year ago

If anyone coming here to check for external commands autocompletion, nushell supports external completers and checkout carapace

Contributions to improve our internal completion story are still welcome nevertheless. Especially extensions to our completion engine that make it possible to use definition formats provided by other tools. We should strive to make the setup as seemless as possible.

rsteube commented 7 months ago

FYI: there's also a manpage parser in murex.

See carapace-spec-man. Can't really recommend it though. Manpages are too much of a mess.

fdncred commented 7 months ago

I looked into ROFF parsers too and I'm not sure how this "standard" ever existed. It's so complicated and such a mess, from what I remember. Now if we could just get someone to write a translator in rust. :)

ysthakur commented 6 months ago

I have a crate where I'm working on this, but I haven't managed to port or test all of the parsers that the Fish script has (mainly because I don't have samples of every kind of manpage on my own computer to test out). Any help with that would be appreciated :)