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

[Feature Request] Completion #5

Open
tyler71 opened this issue Sep 25, 2020 · 2 comments
Open

[Feature Request] Completion #5

tyler71 opened this issue Sep 25, 2020 · 2 comments

Comments

@tyler71
Copy link
Contributor

tyler71 commented Sep 25, 2020

It'd be nice to have completion of available images for dockit when installed, if the environment allows for it.

For example, with zsh and oh-my-zsh installed on ubuntu, placing this in ~/.zshrc makes completion work nicely.

complete -C "docker images --format '{{.Repository}}:{{.Tag}}'" dockit

complete with zsh

@awkspace
Copy link
Owner

I like the idea. I'll have a look around myself, but do you know of any examples of installers that automatically modify shell startup scripts? I want to do it safely, though I know some refuse to do it at all (pyenv-installer will only print what you need to add, for example).

@tyler71
Copy link
Contributor Author

tyler71 commented Sep 26, 2020

Instead of editing ~/.zshrc or ~/.bashrc, files can be placed for zsh / bash utilizing their autocompletion.

I believe for bash, the completions should be placed here, as that's where docker put theirs.

/usr/share/bash-completion/completions

This will list all the images (no auto complete with this implementation)

# Placed in /usr/share/bash-completion/completions/dockit
# dockit(1) completion                                       -*- shell-script -*-
_dockit()
{
	local images
	images="$( docker images --format '{{.Repository}}:{{.Tag}}' )"
	COMPREPLY=( $( compgen -W "$images" -- "$cur" ) )
	__ltrim_colon_completions "$cur"
}
complete -F _dockit dockit

For zsh, placing this completion file and having oh-my-zsh seems to replicate the behavior. However, their ~/.zshrc needs to have this line. This detail may be better served as a faq entry however as most users using zsh shouldn't have a problem.

autoload bashcompinit && bashcompinit

Placed in /usr/share/zsh/vendor-completions/_dockit

#compdef dockit

complete -C "docker images --format '{{.Repository}}:{{.Tag}}'" dockit

Sites for reference
https://github.com/zsh-users/zsh-completions
https://github.com/zsh-users/zsh-completions/blob/master/zsh-completions-howto.org

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