click icon indicating copy to clipboard operation
click copied to clipboard

tab completion during interactive prompts

Open chaoflow opened this issue 11 years ago • 10 comments

It would be nice if click would support tab completion when prompting for files and paths.

chaoflow avatar Jun 26 '14 11:06 chaoflow

The shell command read -e offers a prompt with tab completion. However, the -e flag is a bashism, so we can only use this when bash is installed. I think only offering tab completion when bash is installed is a reasonable tradeoff to make, as any custom tab-completion would require much more code.

untitaker avatar Jun 30 '14 17:06 untitaker

Personally, I'm a zsh user, but given a bash solution I'd figure something.

On the other hand, tab completion shouldn't be too difficult in pure python.

chaoflow avatar Jun 30 '14 22:06 chaoflow

The solution i proposed only requires it to be installed, not to be used.

untitaker avatar Jul 01 '14 03:07 untitaker

Good point. However, read -e is using readline, which is GPL, which I'm not sure whether we can use in click.

Independent of bash vs python, displaying matches feels more complex than gathering the matches.

Would bash's read -e solve that for us?

chaoflow avatar Jul 01 '14 08:07 chaoflow

It does the whole prompt-thing for us and saves the result in a shell variable. I think i'll try to write a first implementation later this evening. @mitsuhiko Thoughts?

untitaker avatar Jul 01 '14 16:07 untitaker

The whole completion support needs rewriting or cleaning up. It absolutely makes no sense currently. It's wrong and mostly works by chance :)

mitsuhiko avatar Jul 02 '14 11:07 mitsuhiko

I don't think the command completion for bash is technically related to this.

untitaker avatar Jul 02 '14 11:07 untitaker

Um.. anything on this? I see that there's a PR on this at #428 ... but it's sorta old.

nir0s avatar Jun 28 '16 19:06 nir0s

Do we have tab completion for choice option prompts? Does this fit this issues scope after adjusting title and description or shall I open a new issue?

chaoflow avatar Sep 04 '17 07:09 chaoflow

The completion system has been totally rewritten in #1622. The prompt system can get completions for a parameter by calling param.shell_complete(ctx, incomplete). #181 explored using readline, but that's not guaranteed to be built with Python, and there's an issue around license. It also points out that there are other nice solutions like prompt-toolkit. I'd like to avoid adding optional dependencies, so the first thing that needs to be done is to design a way for prompt to be customized more, so extensions could provide implementations.

davidism avatar Oct 03 '20 22:10 davidism