trurl icon indicating copy to clipboard operation
trurl copied to clipboard

Shell Completions

Open jacobmealey opened this issue 1 year ago • 5 comments

As we are moving toward a pretty stable set of command line options, I think it would be nice to provide completions for common shells.

If folks are interested in this I can start working on this soon.

IIRC curl has completions turned off by default, is that something we would want to do as well?

jacobmealey avatar Sep 04 '24 11:09 jacobmealey

If folks are interested in this I can start working on this soon.

Sounds like a great thing to offer. Do you plan to aim for a specific shell or doing something generic that can be used for multiple shells?

curl has completions turned off by default

I'm not sure what this means. How does curl have completions turned off and where does it do this?

bagder avatar Sep 04 '24 12:09 bagder

How does curl have completions turned off and where does it do this?

I'm not familiar with what curl does, I have only built it from scratch a handful of times for testing trurl, I was just looking through how curl handles completions. I was referring to a comment in this issue: https://github.com/curl/curl/issues/13255

A standard autoconf build wouldn't have done it it. Now, they will be created when the flag(s) are given.

Maybe what I meant to say is some of the curl completions appear to be behind a flag when configuring the build. would we want the completions for trurl to be an optional step in the install process?

Do you plan to aim for a specific shell or doing something generic that can be used for multiple shells?

I feel like something more generic would be best, I was thinking it would be a script that generates for bash and zsh (these are the ones I am okay with) but is easy to extend it and generate for a different shell. There might also be an existing tool that does this as well.

jacobmealey avatar Sep 04 '24 13:09 jacobmealey

It seems like it should be pretty straight forward to retrofit this script to work with trurl: https://github.com/curl/curl/blob/master/scripts/completion.pl

jacobmealey avatar Sep 04 '24 13:09 jacobmealey

The curl project has that completion.pl script that generates setups for two shells. Most notably it does not do it for bash, which I believe is still a very popular shell. (The completions for bash that we see in other places is done by others. It is a little suboptimal but nothing I can do anything about.)

This script has been criticized for requiring the actual executable to run, since it makes it impossible to generate completions when cross-compiling etc so there is a TODO item somewhere to rewrite it to instead based its logic on source code/static files.

bagder avatar Sep 05 '24 09:09 bagder

Thanks for the context. I will look into something that creates completions without needing to execute trurl. I think a good goal is zsh, bash and fish - and some clever way to add more shells later? It might be across a few PRs, probably one for each shell.

some interesting avenues: https://github.com/nevesnunes/sh-manpage-completions https://github.com/RobSis/zsh-completion-generator https://fishshell.com/docs/current/cmds/fish_update_completions.html

another avenue could be using libclang for python and manually pulling out the string from help(), but that seems like it be annoying if we change what help is doing.

jacobmealey avatar Sep 05 '24 14:09 jacobmealey

I've been playing around with this a bit more, and have it working pretty well for ZSH. The script I wrote to generates the completions uses the trurl.1 file. Is there any appetite to bring the cd2nroff script into the trurl repo so we can have all the scripts for cutting releases / generating install artifacts?

making it work with the markdown wouldn't be too much work, but I just thought it would be worth bringing up EDIT: Making it work with the md file was a 3 line change.

jacobmealey avatar Dec 11 '24 00:12 jacobmealey

Making it work with the md file was a 3 line change.

:grinning: I think that is a better approach since the .md is the source. That said, I'm certainly not against bringing over the cd2nroff script if it helps us.

bagder avatar Dec 13 '24 13:12 bagder

Perfect, its shaping up pretty well with the .md file. Ive got the day off so I'm hoping to get it PR ready by this evening!

jacobmealey avatar Dec 13 '24 13:12 jacobmealey

#379 brought zsh completions. It should work as a recipe for how other completions can be made as well.

bagder avatar Jan 04 '25 22:01 bagder

Thanks @bagder now that it's pulled in I can start working on those as well!

jacobmealey avatar Jan 05 '25 01:01 jacobmealey

Adding the cd2nroff script to this package would help packagers who have to at least install the curl sources to extract that script. With lesspipe installed, you can extract from distro sources (or equivalents on deb or rpm distros), using for example: $ less /usr/src/curl/curl-8.11.1-1.x86_64/dist/curl/curl-8.11.1-1-src.tar.xz:curl-8.11.1-1.src/curl-8.11.1.tar.xz:curl-8.11.1/scripts/cd2nroff > .../scripts/cd2nroff && chmod a+rx .../scripts/cd2nroff

BrianInglis avatar Jan 11 '25 16:01 BrianInglis