fzf support for docker

Created on 7 Dec 2016  Â·  3Comments  Â·  Source: junegunn/fzf

It would be great to have fzf completion for docker. For example docker run **<TAB> – fzf prompt populated from docker images command, docker exec **<TAB> analogously to previous case but with content from docker ps, etc. There are more command that could be completed (like docker save, docker kill and more), but I would like to know if you are interested in adding such functionality to fzf in first place. Thanks.

Most helpful comment

You may also want to check my fuzzy completion for bash that also handles docker argument completion (and zsh!)
https://github.com/Mike-Now/docker-fzf-completion #shamelessplug

All 3 comments

Thanks for the suggestion, but I'm not interested in extending the scope of the shell extension included in this repository not to increase maintenance burden.

Extra completion functions can go to the wiki page or can be provided as separate, third-party repositories.

Please refer to https://github.com/junegunn/fzf/wiki/Examples-(completion) for custom completion functions.

@fenuks I made a small example working with Docker and fzf:

# Custom fuzzy completion for "docker" command
#   e.g. docker **<TAB>
_fzf_complete_docker() {
  ARGS="$@"
  if [[ $ARGS = 'docker ** docker' ]]; then
    _fzf_complete "--multi --reverse" "$@" < <(
        echo 'images'
        echo 'inspect'
        echo 'ps -a'
        echo 'rmi -f'
        echo 'rm'
        echo 'stop'
        echo 'start'
    )
  elif [[ $ARGS = 'docker ** rmi' || $ARGS = 'docker ** -f' ]]; then
    _fzf_complete "--multi --reverse" "$@" < <(
        docker images --format '{{.Repository}}:{{.Tag}}'
    )
  elif [[ $ARGS = 'docker ** start' || $ARGS = 'docker ** stop' || $ARGS = 'docker ** rm' ]]; then
    _fzf_complete "--multi --reverse" "$@" < <(
        docker ps -a --format '{{.Names}}'
    )
  fi
}
[ -n "$BASH" ] && complete -F _fzf_complete_docker -o default -o bashdefault docker

Basically you can completion with this commands:

docker **<TAB>
docker rmi **<TAB>
docker rmi -f **<TAB>
docker start **<TAB>
docker stop **<TAB>
docker rm **<TAB>

Those are the ones I use every day, you can add more.
Hope you find it useful.

You may also want to check my fuzzy completion for bash that also handles docker argument completion (and zsh!)
https://github.com/Mike-Now/docker-fzf-completion #shamelessplug

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ahmedelgabri picture ahmedelgabri  Â·  3Comments

skamsie picture skamsie  Â·  3Comments

jan-warchol picture jan-warchol  Â·  3Comments

sandric picture sandric  Â·  3Comments

firedev picture firedev  Â·  3Comments