todoman icon indicating copy to clipboard operation
todoman copied to clipboard

Provide autocompletion for bash and zsh

Open WhyNotHugo opened this issue 8 years ago • 5 comments

WhyNotHugo avatar Mar 09 '17 02:03 WhyNotHugo

Hi @hobarrera,

I do have a basic version of tab completion for bash (can also be used in zsh with the compatibility layer, of course). I can open a pull request, but I need to know where to actually put the file in the project. Should we have a new folder completion or something?

ghost avatar Jul 21 '17 12:07 ghost

Hey, thanks!

A new contrib directory would've fine. If you can, installation instructions for these would be nice (though I write those if you've no idea how).

WhyNotHugo avatar Jul 21 '17 14:07 WhyNotHugo

I opened a pull request just now. Let's continue the discussion there.

ghost avatar Jul 24 '17 07:07 ghost

Recently I've been working on trying to get completion working with fish, and realized that click has built-in support to generate completions for a variety of shells (see #543 for a little more context):

  1. click docs on generating completions for a given shell
  2. click docs on customizing argument and option value completions

Right now you can get (1) out of the box w/ todo; however, (2) requires implementing a shell_complete method per argument or option. It's not perfect, but I've got a sample for todo new --list in this fork: https://github.com/johnjameswhitman/todoman/blob/4a00d7ecb20028f4d8f3173928e4cd24849e97c4/todoman/cli.py#L350-L370

Unfortunately, it doesn't seem like you can access the AppContext that cli sets up, so you have to create it within the shell completion function. This also means you don't have access to the config argument passed into the main cli command (at least, I can't figure out how to find it after some debugging). It seems like the completions in contrib also have this limitation, and either parse the default config location (zsh) or run todo w/o specifying a config (bash). So, implementing shell completion within todoman/cli.py may make it easier to maintain across both bash and zsh, plus enable fish.

Is adding click-based support for value-completions a contribution the project would welcome?

Edit: It looks like the interface for completion changed between click v7 (uses autocompletion) and v8 (uses shell_complete). I see todoman currently allows click v7...if we were to implement support, then perhaps that's tied to a major-version bump on todoman that pins to click v8+. https://github.com/pimutils/todoman/blob/31a96d414e2e685be90bfe3c7f067934252d6278/pyproject.toml#L29

johnjameswhitman avatar Oct 18 '23 18:10 johnjameswhitman

Is adding click-based support for value-completions a contribution the project would welcome?

We currently have hand-crafted completions for zsh and bash. click-based completions are welcome as long as they don't introduce any regressions.

click 8.0.0 is not very new. I'm fine with making it the minimum supported version.

WhyNotHugo avatar Oct 19 '23 09:10 WhyNotHugo