-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Add go template shell completion for --format #10099
Add go template shell completion for --format #10099
Conversation
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Luap99 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Very cool, since I have a hard time remembering these and often have to do an inspect to find the names. I would love to have a demo of this at a podman monthly meeting. LGTM |
You are my hero. Is there any way to make it work with |
Not sure if I understand this question correctly. The
|
Oh, interesting. The |
This is really weird. I keep getting myself into a place where More weirdnesses:
|
Only --format does not work but other completions such as subcommands or other flags work? I have no idea what could cause this. You could do a
Not for me.
I am also unable to reproduce this one. It tried for some time with all combinations but it worked correct as long as quotes are used. I have not configured anything in zsh, maybe you have some special settings which causes this to fail.
OK, I know how to fix this one. |
932b73d
to
d9d877f
Compare
That was it:
git reports that I added this in 2014, and I no longer remember why. I'm sorry for wasting your time. I should've tried tabula rasa before reporting that. (As for bash, I don't use it, so I don't really care if it works or not.) Anyhow, here's one I did try with a plain zsh setup: $ ./bin/podman info --format '{{.H' <--- hit TAB
actual$ ./bin/podman info --format '{{.Host}} |' '|' indicates cursor
wanted$ ./bin/podman info --format '{{.Host.|' |
This should be possible. I think it is worth to do for some structs with many fields but not for everything since this would defeat my nice simple solution. |
Simple is good. Thank you for your quick response. |
d9d877f
to
1d7b75f
Compare
Updated I add a dot instead of the braces when the field is a struct.
|
The --format flags accepts go template strings. I use this often but I consistently forget the field names. This commit adds a way to provide shell completion for the --format flag. It works by automatically receiving the field names with the reflect package from the given struct. This requires almost no maintenance since this ensures that we always use the correct field names. This also works for nested structs. ``` $ podman ps --format "{{.P" {{.Pid}} {{.PIDNS}} {{.Pod}} {{.PodName}} {{.Ports}} ``` NOTE: This only works when you use quotes otherwise the shell does not provide completions. Also this does not work for fish at the moment. Signed-off-by: Paul Holzinger <[email protected]>
1d7b75f
to
d81021e
Compare
And it works beautifully. I appreciate this SO MUCH! |
/lgtm |
The --format flags accepts go template strings. I use this often but I
consistently forget the field names. This commit adds a way to provide
shell completion for the --format flag. It works by automatically
receiving the field names with the reflect package from the given
struct. This requires almost no maintenance since this ensures that we
always use the correct field names. This also works for nested structs.
NOTE: This only works when you use quotes otherwise the shell does not
provide completions. Also this does not work for fish at the moment.