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

Suggest completions after argument was "selected" #2260

Closed
moshe5745 opened this issue Mar 12, 2025 · 3 comments
Closed

Suggest completions after argument was "selected" #2260

moshe5745 opened this issue Mar 12, 2025 · 3 comments

Comments

@moshe5745
Copy link

I would like to have completion cycling even if the argument is "selected"
Lets say I have arg1, arg2, arg3, and I choose the first arg1 and press enter.
Right now with my current setup I cant back to "cycling" the args with TAB pressing.

Is this possible with cobra?

@marckhouzam
Copy link
Collaborator

This is not a Cobra thing but a shell thing.
I assume you use zsh?
Once you've selected a completion choice, the shell moves on to the next. If you want to go back, you probably have to delete the argument you accepted. Try Escape then backspace.

If I didn't understand, please provide an explicit example of what you are trying to do

@moshe5745
Copy link
Author

Thanks for the fast response.

Yeah i use zsh. But I am building a CLI tool, hopefully for all platforms.

My explicit example is "reexecution of the command with new argument"(Maybe I should call this issue with this).

For instance:

$: ./my_cli_tool command arg_with_long_name

And then pick from the history the last command(arrow up in zsh).
In this situation you need to delete arg_with_long_name and then enter the new one.
So I am looking for a convenient way for it.

So my first idea was to enable the cycling of the options even if one argument is already selected.
My second idea is to somehow make the shell remember the last command without the argument, so when I press arrow up it will write:

$: ./my_cli_tool command

Is it possible?
Any other ideas?

@marckhouzam
Copy link
Collaborator

marckhouzam commented Mar 12, 2025

I don’t believe your first idea is possible.
As for the shell remembering the command without the argument, I think what you need is a key binding that’s gonna insert the last command. For example, on my ZSH, typing escape+. will insert the last argument of the previous command. I haven’t found a shortcut to insert the previous command. But if you do, please let me know, this is something I would also like to do be able to do

Beside all this, I don’t believe cobra can help you with this requirement. It’s a shell thing.

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

No branches or pull requests

2 participants