fzf-docker icon indicating copy to clipboard operation
fzf-docker copied to clipboard

Support for docker-compose commands

Open tuxflo opened this issue 2 years ago • 2 comments

Hi, at first thanks for the nice plugin it seems to work fine so far. In my current project I have a lot to do with docker-compose and I thought I could extend the plugin to support docker-compose too. I tried to add

  elif [[ $ARGS == 'docker-compose stop'* || $ARGS == 'docker-compose kill'* || $ARGS == 'docker-compose up'* ]]; then
    _fzf_complete "--multi --header-lines=1" "$@" < <(
      docker-compose ps
    )

to get the output of docker-compose ps as a fzf preview but it's not working. It looks like the custom autocomplete isn't triggered at all (**<TAB> generates the normal file autocompletion list).

Any ideas on how to fix that?

tuxflo avatar Sep 02 '21 08:09 tuxflo

Hey!

If you have a look at the bottom of the file, you'll notice that we declare the completion for the specific docker command:

#                                                                             v--- here
[ -n "$BASH" ] && complete -F _fzf_complete_docker -o default -o bashdefault docker

You'd need to add a new completion function, and declare it with complete for docker-compose instead of docker :blush:

I tried to do it but somehow it doesn't work with docker-compose for me... (but it works if I give it any other name... still investigating that)

pierpo avatar Sep 06 '21 00:09 pierpo

Actually I was wrong, it turns out I didn't even properly understand how all of that was working.

You need to add a function like this, and this should work:

_fzf_complete_docker-compose() {
  ARGS="$@"
  if [[ $ARGS == 'docker-compose'* ]]; then
    _fzf_complete "--multi --reverse" "$@" < <(
      docker-compose ps
    )
  fi
}

You don't even need the complete stuff that I was talking about.

pierpo avatar Sep 06 '21 00:09 pierpo