[Emacs] add Docker Tramp method, move yadm Tramp method
All checks were successful
continuous-integration/drone/push Build is passing

This commit adds the connection method for Docker containers through
Tramp and stores it under the newly created Tramp heading under which
the implementation of the Yadm connection method is implemented.
This commit is contained in:
Lucien Cartier-Tilet 2020-10-21 17:55:22 +02:00
parent 58f895743e
commit 31eb64c2ba
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA

View File

@ -3908,13 +3908,56 @@
\{\{\{nyqy($1)\}\}\} $0 \{\{\{nyqy($1)\}\}\} $0
#+END_SRC #+END_SRC
** Yadm ** Tramp configuration
:PROPERTIES:
:CUSTOM_ID: User_Configuration-Tramp_configuration-acb4733b
:END:
*** Docker
:PROPERTIES:
:CUSTOM_ID: User_Configuration-Tramp_configuration-Docker-31573fdf
:END:
It is completely possible with Tramp to connect ot a docker container and
modify files inside of it. It is not supported natively, but we can add it
quite easily. Be aware, I am not the author of this code, you can find its
original source [[https://www.emacswiki.org/emacs/TrampAndDocker][here]]. First, lets add the Docker protocol to Tramp:
#+BEGIN_SRC emacs-lisp
(push
(cons
"docker"
'((tramp-login-program "docker")
(tramp-login-args (("exec" "-it") ("%h") ("/bin/bash")))
(tramp-remote-shell "/bin/sh")
(tramp-remote-shell-args ("-i") ("-c"))))
tramp-methods)
#+END_SRC
Now that the method has been added, lets add some autocompletion for when
we want to connect to a Docker container:
#+BEGIN_SRC emacs-lisp
(defadvice tramp-completion-handle-file-name-all-completions
(around dotemacs-completion-docker activate)
"(tramp-completion-handle-file-name-all-completions \"\" \"/docker:\" returns
a list of active Docker container names, followed by colons."
(if (equal (ad-get-arg 1) "/docker:")
(let* ((dockernames-raw (shell-command-to-string "docker ps --format '{{.Names}}:'"))
(dockernames (cl-remove-if-not #'(lambda (dockerline)
(string-match ":$" dockerline))
(split-string dockernames-raw "\n"))))
(setq ad-return-value dockernames))
ad-do-it))
#+END_SRC
And thats it! it is now possible to connect to a docker container with
something like ~/docker:conlangdict_server/~ as the path given in
~find-file~.
*** Yadm
:PROPERTIES: :PROPERTIES:
:CUSTOM_ID: User_Configuration-Yadm-4344fec3 :CUSTOM_ID: User_Configuration-Yadm-4344fec3
:END: :END:
yadm is the utility I use for managing my dotfiles, and it is a wrapper ~yadm~ is the utility I use for managing my dotfiles, and it is a wrapper In
In order to manage my dotfiles, I use the following shortcut to launch Magit order to manage my dotfiles, I use the following shortcut to launch Magit
Status for yadm: Status for ~yadm~:
#+BEGIN_SRC emacs-lisp #+BEGIN_SRC emacs-lisp
(spacemacs/declare-prefix "oy" "yadm status") (spacemacs/declare-prefix "oy" "yadm status")
(spacemacs/set-leader-keys "oy" (lambda () (interactive) (magit-status "/yadm::"))) (spacemacs/set-leader-keys "oy" (lambda () (interactive) (magit-status "/yadm::")))