From: Michael Albinus Date: Tue, 27 Sep 2022 16:46:28 +0000 (+0200) Subject: Some tramp-docker.el adaptions X-Git-Tag: emacs-29.0.90~1856^2~187 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=c273e26af58aab340b470595874893b23dab208d;p=emacs.git Some tramp-docker.el adaptions * lisp/net/tramp-docker.el (tramp-docker--completion-function): Add ;;;###tramp-autoload cookie. Make implementation more robust. (tramp-methods) Use `tramp-default-remote-shell'. --- diff --git a/lisp/net/tramp-docker.el b/lisp/net/tramp-docker.el index 40257a4a12c..918469908af 100644 --- a/lisp/net/tramp-docker.el +++ b/lisp/net/tramp-docker.el @@ -53,23 +53,26 @@ (defconst tramp-docker-method "docker" "Tramp method name to use to connect to Docker containers.") +;;;###tramp-autoload (defun tramp-docker--completion-function (&rest _args) "List Docker containers available for connection. This function is used by `tramp-set-completion-function', please see its function help for a description of the format." - (let* ((raw-list (shell-command-to-string - (concat tramp-docker-program - " ps --format '{{.ID}}\t{{.Names}}'"))) - (lines (split-string raw-list "\n")) - (names (mapcar (lambda (line) - (let ((words (split-string line "\t"))) - (or (nth 1 words) (nth 0 words)))) - lines)) - (machines (seq-take-while (lambda (name) name) names))) - (mapcar (lambda (m) (list nil m)) machines))) - -;; todo: check tramp-async-args and tramp-direct-async + (when-let ((raw-list (shell-command-to-string + (concat tramp-docker-program + " ps --format '{{.ID}}\t{{.Names}}'"))) + (lines (split-string raw-list "\n" 'omit)) + (names (mapcar + (lambda (line) + (when (string-match + (rx bol (group (1+ nonl)) + "\t" (? (group (1+ nonl))) eol) + line) + (or (match-string 2 line) (match-string 1 line)))) + lines))) + (mapcar (lambda (m) (list nil m)) (delq nil names)))) + ;;;###tramp-autoload (tramp--with-startup (push `(,tramp-docker-method @@ -78,8 +81,8 @@ see its function help for a description of the format." ("-it") ("-u" "%u") ("%h") - ("/bin/sh"))) - (tramp-remote-shell "/bin/sh") + ("%l"))) + (tramp-remote-shell ,tramp-default-remote-shell) (tramp-remote-shell-login ("-l")) (tramp-remote-shell-args ("-i" "-c"))) tramp-methods)