]> git.eshelyaron.com Git - emacs.git/commitdiff
Add Tramp distrobox method
authorMichael Albinus <michael.albinus@gmx.de>
Wed, 29 May 2024 16:29:52 +0000 (18:29 +0200)
committerEshel Yaron <me@eshelyaron.com>
Thu, 30 May 2024 14:26:09 +0000 (16:26 +0200)
* doc/misc/tramp.texi (Inline methods) <distrobox>: Add.

* etc/NEWS: Mention Tramp distrobox method.

* lisp/net/tramp-container.el (tramp-distrobox-program): New defcustom.
(tramp-distrobox-method): New defconst.
(tramp-distrobox--completion-function)
(tramp-enable-distrobox-method): New defuns.  (Bug#71200)
(tramp-docker-method, tramp-dockercp-method)
(tramp-podman-method, tramp-podmancp-method)
(tramp-kubernetes-method, tramp-flatpak-method)
(tramp-apptainer-method, tramp-nspawn-method): Adapt docstring.

* test/lisp/net/tramp-tests.el (tramp--test-box-p): Rename from
`tramp--test-toolbox-p'.  Add distrobox.  Adapt callees.

(cherry picked from commit 17c23a46c3d834e7dc9f153e86a51242b3867b74)

doc/misc/tramp.texi
etc/NEWS
lisp/net/tramp-container.el
test/lisp/net/tramp-tests.el

index 05403956ff9ea2d4aa8668258c89a6de0280526f..9d53de1a41e594572018d662c3e7bc6d8311d673 100644 (file)
@@ -1005,15 +1005,19 @@ in a pod is used.
 This method does not support user names.
 
 @item @option{toolbox}
+@item @option{distrobox}
 @cindex method @option{toolbox}
 @cindex @option{toolbox} method
+@cindex method @option{distrobox}
+@cindex @option{distrobox} method
 
-Integration of Toolbox system containers.  The host name may be either
-a container's name or ID, as returned by @samp{toolbox list -c}.
-Without a host name, the default Toolbox container for the host will
-be used.
+Integration of Toolbox or Distrobox system containers, respectively.
+The host name may be either a container's name or ID, as returned by
+@samp{toolbox list -c} or @samp{distrobox list}.  Without a host name,
+the default Toolbox container for the host will be used.  There is no
+such default for Distrobox.
 
-This is an optional method, @pxref{Optional methods}.  It does not
+These are optional methods, @pxref{Optional methods}.  They do not
 support user names.
 
 @item @option{flatpak}
index 3efd5612f07d9f49d135728ac8c501f48ba380cd..c9c9def537dc9f4d2ff904e931d6ac18ac9d2279 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1166,7 +1166,7 @@ mode line.  'header' will display in the header line;
 +++
 *** New user option 'which-func-update-delay'.
 This replaces the user option 'idle-update-delay', which was previously
-used to control the delay before `which-function-mode` updated its
+used to control the delay before 'which-function-mode' updated its
 display.  The user option 'idle-update-delay', which was only used by
 Which Function mode, is now obsolete.
 
@@ -1195,10 +1195,11 @@ These are the external methods counterparts of "docker" and "podman".
 
 +++
 *** New optional connection methods for containers.
-Tere are new optional connection methods "toolbox", "flatpak",
-"apptainer" and "nspawn".  They allow accessing system containers
-provided by Toolbox, sandboxes provided by Flatpak, instances managed by
-Apptainer, or accessing systemd-based light-weight containers..
+There are new optional connection methods "toolbox", "distrobox",
+"flatpak", "apptainer" and "nspawn".  They allow accessing system
+containers provided by Toolbox or Distrobox, sandboxes provided by
+Flatpak, instances managed by Apptainer, or accessing systemd-based
+light-weight containers..
 
 +++
 *** Connection method "kubernetes" supports now optional container name.
@@ -2196,7 +2197,7 @@ and 'closure' is the common parent type of 'interpreted-function'
 and 'byte-code-function'.
 
 Those new types come with the associated new predicates 'closurep' and
-`interpreted-function-p' as well as a new constructor
+'interpreted-function-p' as well as a new constructor
 'make-interpreted-closure'.
 
 ** New function 'help-fns-function-name'.
index 2886e25d16bd2c308cacbc63d2c4ce5ae4a054f1..cc1d9f457cca0a8218fda8b81de4e2527859c079 100644 (file)
 ;;
 ;;
 ;;
+;; Open a file on an existing Distrobox container:
+;;
+;;     C-x C-f /distrobox:CONTAINER:/path/to/file
+;;
+;; Where:
+;;     CONTAINER     is the container to connect to.
+;;
+;; If the container is not running, it is started.
+;;
+;;
+;;
 ;; Open a file on a running Flatpak sandbox:
 ;;
 ;;     C-x C-f /flatpak:SANDBOX:/path/to/file
@@ -153,6 +164,14 @@ If it is nil, the default context will be used."
   :type '(choice (const "toolbox")
                  (string)))
 
+;;;###tramp-autoload
+(defcustom tramp-distrobox-program "distrobox"
+  "Name of the Distrobxx client program."
+  :group 'tramp
+  :version "30.1"
+  :type '(choice (const "distrobox")
+                 (string)))
+
 ;;;###tramp-autoload
 (defcustom tramp-flatpak-program "flatpak"
   "Name of the Flatpak client program."
@@ -178,41 +197,45 @@ If it is nil, the default context will be used."
 
 ;;;###tramp-autoload
 (defconst tramp-docker-method "docker"
-  "Tramp method name to use to connect to Docker containers.")
+  "Tramp method name to connect to Docker containers.")
 
 ;;;###tramp-autoload
 (defconst tramp-dockercp-method "dockercp"
-  "Tramp method name to use to connect to Docker containers.
+  "Tramp method name to connect to Docker containers.
 This is for out-of-band connections.")
 
 ;;;###tramp-autoload
 (defconst tramp-podman-method "podman"
-  "Tramp method name to use to connect to Podman containers.")
+  "Tramp method name to connect to Podman containers.")
 
 ;;;###tramp-autoload
 (defconst tramp-podmancp-method "podmancp"
-  "Tramp method name to use to connect to Podman containers.
+  "Tramp method name to connect to Podman containers.
 This is for out-of-band connections.")
 
 ;;;###tramp-autoload
 (defconst tramp-kubernetes-method "kubernetes"
-  "Tramp method name to use to connect to Kubernetes containers.")
+  "Tramp method name to connect to Kubernetes containers.")
 
 ;;;###tramp-autoload
 (defconst tramp-toolbox-method "toolbox"
-  "Tramp method name to use to connect to Toolbox containers.")
+  "Tramp method name to connect to Toolbox containers.")
+
+;;;###tramp-autoload
+(defconst tramp-distrobox-method "distrobox"
+  "Tramp method name to connect to Distrobox containers.")
 
 ;;;###tramp-autoload
 (defconst tramp-flatpak-method "flatpak"
-  "Tramp method name to use to connect to Flatpak sandboxes.")
+  "Tramp method name to connect to Flatpak sandboxes.")
 
 ;;;###tramp-autoload
 (defconst tramp-apptainer-method "apptainer"
-  "Tramp method name to use to connect to Apptainer instances.")
+  "Tramp method name to connect to Apptainer instances.")
 
 ;;;###tramp-autoload
 (defconst tramp-nspawn-method "nspawn"
-  "Tramp method name to use to connect to systemd-nspawn containers.")
+  "Tramp method name to connect to systemd-nspawn containers.")
 
 ;;;###tramp-autoload
 (defmacro tramp-skeleton-completion-function (method &rest body)
@@ -381,6 +404,7 @@ see its function help for a description of the format."
     (when-let ((raw-list (shell-command-to-string (concat program " list -c")))
               ;; Ignore header line.
                (lines (cdr (split-string raw-list "\n" 'omit)))
+              ;; We do not show container IDs.
                (names (tramp-compat-seq-keep
                       (lambda (line)
                         (when (string-match
@@ -391,6 +415,28 @@ see its function help for a description of the format."
                        lines)))
       (mapcar (lambda (name) (list nil name)) names))))
 
+;;;###tramp-autoload
+(defun tramp-distrobox--completion-function (method)
+  "List Distrobox containers available for connection.
+
+This function is used by `tramp-set-completion-function', please
+see its function help for a description of the format."
+  (tramp-skeleton-completion-function method
+    (when-let ((raw-list (shell-command-to-string (concat program " list")))
+              ;; Ignore header line.
+               (lines (cdr (split-string raw-list "\n" 'omit)))
+              ;; We do not show container IDs.
+               (names (tramp-compat-seq-keep
+                      (lambda (line)
+                        (when (string-match
+                               (rx bol (1+ (not space))
+                                   (1+ space) "|" (1+ space)
+                                   (group (1+ (not space))) space)
+                               line)
+                          (match-string 1 line)))
+                       lines)))
+      (mapcar (lambda (name) (list nil name)) names))))
+
 ;;;###tramp-autoload
 (defun tramp-flatpak--completion-function (method)
   "List Flatpak sandboxes available for connection.
@@ -595,6 +641,26 @@ see its function help for a description of the format."
    tramp-toolbox-method
    `((tramp-toolbox--completion-function ,tramp-toolbox-method))))
 
+;;;###tramp-autoload
+(defun tramp-enable-distrobox-method ()
+  "Enable connection to Distrobox containers."
+  (add-to-list 'tramp-methods
+              `(,tramp-distrobox-method
+                (tramp-login-program ,tramp-distrobox-program)
+                (tramp-login-args (("enter")
+                                   ("-n" "%h")
+                                   ("--" "%l")))
+                ;(tramp-direct-async (,tramp-default-remote-shell "-c"))
+                (tramp-remote-shell ,tramp-default-remote-shell)
+                (tramp-remote-shell-login ("-l"))
+                (tramp-remote-shell-args ("-c"))))
+
+  (add-to-list 'tramp-completion-multi-hop-methods tramp-distrobox-method)
+
+  (tramp-set-completion-function
+   tramp-distrobox-method
+   `((tramp-distrobox--completion-function ,tramp-distrobox-method))))
+
 ;;;###tramp-autoload
 (defun tramp-enable-flatpak-method ()
   "Enable connection to Flatpak sandboxes."
index 474bb4c350cdd60016dfe80f65bca6ba164e9863..6f66352c4539ac775abe141ecf2b71f583141896 100644 (file)
@@ -6762,6 +6762,13 @@ This is used in tests which we don't want to tag
    (not (and (tramp--test-adb-p)
             (string-match-p (rx multibyte) default-directory)))))
 
+(defun tramp--test-box-p ()
+  "Check, whether the toolbox or distrobox method is used.
+This does not support `tramp-test45-asynchronous-requests'."
+  (string-match-p
+   (rx bol (| "toolbox" "distrobox") eol)
+   (file-remote-p ert-remote-temporary-file-directory 'method)))
+
 (defun tramp--test-container-p ()
   "Check, whether a container method is used.
 This does not support some special file names."
@@ -6912,12 +6919,6 @@ This does not support special file names."
   (string-equal
    "telnet" (file-remote-p ert-remote-temporary-file-directory 'method)))
 
-(defun tramp--test-toolbox-p ()
-  "Check, whether the toolbox method is used.
-This does not support `tramp-test45-asynchronous-requests'."
-  (string-equal
-   "toolbox" (file-remote-p ert-remote-temporary-file-directory 'method)))
-
 (defun tramp--test-windows-nt-p ()
   "Check, whether the locale host runs MS Windows."
   (eq system-type 'windows-nt))
@@ -7406,7 +7407,7 @@ process sentinels.  They shall not disturb each other."
   (skip-unless (not (tramp--test-container-p)))
   (skip-unless (not (tramp--test-sshfs-p)))
   (skip-unless (not (tramp--test-telnet-p)))
-  (skip-unless (not (tramp--test-toolbox-p)))
+  (skip-unless (not (tramp--test-box-p)))
   (skip-unless (not (tramp--test-windows-nt-p)))
 
   (with-timeout