awkspace / dockit

Jump into a Docker image.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature Request] Completion

tyler71 opened this issue · comments

commented

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

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).

commented

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