emacs-pe / docker-tramp.el

TRAMP integration for docker containers
339 stars 26 forks source link

Add proper completion with TRAMP multi-hops #17

Open olessavluk opened 6 years ago

olessavluk commented 6 years ago

Hi,

When I use TRAMP multi-hops syntax, for example /ssh:example.com|docker: in the suggestions, I see the list of my local containers, but would like to see the remote one (from example.com).

Is it possible to make suggestions that use remote docker?

olessavluk commented 6 years ago

I've tried to rewrite function for suggestions using process-file which is aware of the default-directory which means it can be used over tramp:

(defun docker-tramp--running-containers ()
  "Collect docker running containers.
Return a list of containers of the form: \(ID NAME\)"
  (let* ((args (append docker-tramp-docker-options
                       (list "ps" "--format" "{{.ID}}:{{.Names}}")))
         (ps (ignore-errors
               (with-output-to-string
                 (apply #'process-file docker-tramp-docker-executable nil standard-output nil args))))
         (lines (split-string ps))
         (split-by-collon (lambda (str) (split-string str ":"))))
    (mapcar split-by-collon lines)))

full source - https://github.com/olessavluk/docker-tramp.el/blob/multi-hops/docker-tramp.el#L101

But with this changes, when I use multi-hops syntax I still see my local containers. And after I open some file or a dired buffer using ssh method of TRAMP - I see containers from the remote machine. Which is better but not the desired behavior.

Maybe I can somehow get currently entered value e.g. /ssh:example.com|docker and use it as default-directory and use it to specify which docker whould be executed?

marsam commented 6 years ago

Hi, sorry for the late response. I remember also trying to make this work. I patched process-lines to use process-file instead of call-process which is somewhat similar to your patch, but still tramp does not call the completion functions on the remote server. IIRC tramp-completion-dissect-file-name, the function in charge of filename completions, does not seem to work with hops.

I'll try to check this again this weekend, you can also ask in the tramp mailing list btw.

stardiviner commented 6 years ago

Any update on this function?

olessavluk commented 6 years ago

Hello @stardiviner, As @marsam pointed, seems like there is no way to do this without patching emacs, but I should ask somewhere first.

As a temporary workaround I'm using my fork olessavluk/docker-tramp branch:multi-hops. It is aware of the TRAMP but not aware of the multi-hops (as I've describe previously). In order to use it:

  1. install forked package
    how to install? I'm using spacemacs so just added this to the dotspacemacs-additional-packages: (docker-tramp :location (recipe :fetcher github :repo "olessavluk/docker-tramp.el" :branch "multi-hops"))
    Sure you can do something similar or just clone and require it in your config
    1. open something over TRAMP, I usually open dired buffer
    2. now you should see suggestions from the current TRAMP session
stardiviner commented 6 years ago

@olessavluk Thanks.

dvzubarev commented 6 years ago

Hi @olessavluk, Can you make a PR? It is better than current behavior anyway. It is quite common to open a dired buffer or file on a remote host (e.g. via bookmark) and then add hop to the path.

cl-user commented 2 years ago

Hi,

Maybe I can somehow get currently entered value e.g. /ssh:example.com|docker and use it as default-directory and use it to specify which docker whould be executed?

I did exactly that by using (minibuffer-contents-no-properties) and it works for me. Check out PR #36 when you have time!