Nasser Alkmim <nasser.alk...@gmail.com> writes: Hi,
> Thanks Michael. > I can not find the patch, is it attached to the email? Oops, forgotten. See below. > Best regards, Best regards, Michael.
diff --git a/lisp/tramp-container.el b/lisp/tramp-container.el index 30639cbe..52c78189 100644 --- a/lisp/tramp-container.el +++ b/lisp/tramp-container.el @@ -83,6 +83,15 @@ ;; Where: ;; SANDBOX is the running sandbox to connect to. ;; It could be an application ID, an instance ID, or a PID. +;; +;; +;; +;; Open a file on a running Apptainer instance: +;; +;; C-x C-f /apptainer:INSTANCE:/path/to/file +;; +;; Where: +;; INSTANCE is the running instance to connect to. ;;; Code: @@ -142,6 +151,14 @@ If it is nil, the default context will be used." :type '(choice (const "flatpak") (string))) +;;;###tramp-autoload +(defcustom tramp-apptainer-program "apptainer" + "Name of the Apptainer client program." + :group 'tramp + :version "30.1" + :type '(choice (const "apptainer") + (string))) + ;;;###tramp-autoload (defconst tramp-docker-method "docker" "Tramp method name to use to connect to Docker containers.") @@ -172,6 +189,10 @@ This is for out-of-band connections.") (defconst tramp-flatpak-method "flatpak" "Tramp method name to use to connect to Flatpak sandboxes.") +;;;###tramp-autoload +(defconst tramp-apptainer-method "apptainer" + "Tramp method name to use to connect to Apptainer instances.") + ;;;###tramp-autoload (defmacro tramp-skeleton-completion-function (method &rest body) "Skeleton for `tramp-*-completion-function' with multi-hop support. @@ -373,6 +394,28 @@ see its function help for a description of the format." lines))) (mapcar (lambda (name) (list nil name)) (delq nil names))))) +;;;###tramp-autoload +(defun tramp-apptainer--completion-function (method) + "List Apptainer instances 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 " instance list"))) + ;; Ignore header line. + (lines (cdr (split-string raw-list "\n" 'omit))) + (names (mapcar + (lambda (line) + (when (string-match + (rx bol (group (1+ (not space))) + (1+ space) (1+ (not space)) + (1+ space) (1+ (not space))) + line) + (match-string 1 line))) + lines))) + (mapcar (lambda (name) (list nil name)) (delq nil names))))) + ;;;###tramp-autoload (defvar tramp-default-remote-shell) ;; Silence byte compiler. @@ -477,6 +520,17 @@ see its function help for a description of the format." (tramp-remote-shell-login ("-l")) (tramp-remote-shell-args ("-c")))) + (add-to-list 'tramp-methods + `(,tramp-apptainer-method + (tramp-login-program ,tramp-apptainer-program) + (tramp-login-args (("shell") + ("instance://%h") + ("%h"))) ; Needed for multi-hop check. + ;; (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")))) + (tramp-set-completion-function tramp-docker-method `((tramp-container--completion-function ,tramp-docker-method))) @@ -505,11 +559,16 @@ see its function help for a description of the format." tramp-flatpak-method `((tramp-flatpak--completion-function ,tramp-flatpak-method))) + (tramp-set-completion-function + tramp-apptainer-method + `((tramp-apptainer--completion-function ,tramp-apptainer-method))) + (add-to-list 'tramp-completion-multi-hop-methods tramp-docker-method) (add-to-list 'tramp-completion-multi-hop-methods tramp-podman-method) (add-to-list 'tramp-completion-multi-hop-methods tramp-kubernetes-method) (add-to-list 'tramp-completion-multi-hop-methods tramp-toolbox-method) (add-to-list 'tramp-completion-multi-hop-methods tramp-flatpak-method) + (add-to-list 'tramp-completion-multi-hop-methods tramp-apptainer-method) ;; Default connection-local variables for Tramp.