4747; ; C-x C-f /kubernetes:POD:/path/to/file
4848; ;
4949; ; Where:
50- ; ; POD is the pod to connect to.
51- ; ; By default, the first container in that pod will be
52- ; ; used.
50+ ; ; POD is the pod to connect to.
51+ ; ; By default, the first container in that pod will be
52+ ; ; used.
5353; ;
5454; ; Completion for POD and accessing it operate in the current
5555; ; namespace, use this command to change it:
5858; ;
5959; ;
6060; ;
61- ; ; Open a file on an existing toolbox container via Toolbox :
61+ ; ; Open a file on an existing Toolbox container:
6262; ;
6363; ; C-x C-f /toolbox:CONTAINER:/path/to/file
6464; ;
6767; ;
6868; ; If the container is not running, it is started. If no container is
6969; ; specified, the default Toolbox container is used.
70+ ; ;
71+ ; ;
72+ ; ;
73+ ; ; Open a file on a running Flatpak sandbox:
74+ ; ;
75+ ; ; C-x C-f /flatpak:SANDBOX:/path/to/file
76+ ; ;
77+ ; ; Where:
78+ ; ; SANDBOX is the running sandbox to connect to.
79+ ; ; It could be an application ID, an instance ID, or a PID.
7080
7181; ;; Code:
7282
104114 :type '(choice (const " toolbox" )
105115 (string )))
106116
117+ ; ;;###tramp-autoload
118+ (defcustom tramp-flatpak-program " flatpak"
119+ " Name of the Flatpak client program."
120+ :group 'tramp
121+ :version " 30.1"
122+ :type '(choice (const " flatpak" )
123+ (string )))
124+
107125; ;;###tramp-autoload
108126(defconst tramp-docker-method " docker"
109127 " Tramp method name to use to connect to Docker containers." )
120138(defconst tramp-toolbox-method " toolbox"
121139 " Tramp method name to use to connect to Toolbox containers." )
122140
141+ ; ;;###tramp-autoload
142+ (defconst tramp-flatpak-method " flatpak"
143+ " Tramp method name to use to connect to Flatpak sandboxes." )
144+
123145; ;;###tramp-autoload
124146(defun tramp-container--completion-function (program )
125147 " List running containers available for connection.
@@ -195,6 +217,30 @@ see its function help for a description of the format."
195217 lines)))
196218 (mapcar (lambda (name ) (list nil name)) (delq nil names))))
197219
220+ ; ;;###tramp-autoload
221+ (defun tramp-flatpak--completion-function (&rest _args )
222+ " List Flatpak sandboxes available for connection.
223+ It returns application IDs or, in case there is no application
224+ ID, instance IDs.
225+
226+ This function is used by `tramp-set-completion-function' , please
227+ see its function help for a description of the format."
228+ (when-let ((default-directory tramp-compat-temporary-file-directory)
229+ (raw-list
230+ (shell-command-to-string
231+ (concat tramp-flatpak-program
232+ " ps --columns=instance,application" )))
233+ (lines (split-string raw-list " \n " 'omit ))
234+ (names (mapcar
235+ (lambda (line )
236+ (when (string-match
237+ (rx bol (* space) (group (+ (not space)))
238+ (? (+ space) (group (+ (not space)))) eol)
239+ line)
240+ (or (match-string 2 line) (match-string 1 line))))
241+ lines)))
242+ (mapcar (lambda (name ) (list nil name)) (delq nil names))))
243+
198244; ;;###tramp-autoload
199245(defvar tramp-default-remote-shell ) ; ; Silence byte compiler.
200246
@@ -253,6 +299,17 @@ see its function help for a description of the format."
253299
254300 (add-to-list 'tramp-default-host-alist `(, tramp-toolbox-method nil " " ))
255301
302+ (add-to-list 'tramp-methods
303+ `(, tramp-flatpak-method
304+ (tramp-login-program , tramp-flatpak-program )
305+ (tramp-login-args ((" enter" )
306+ (" %h" )
307+ (" %l" )))
308+ (tramp-direct-async (, tramp-default-remote-shell " -c" ))
309+ (tramp-remote-shell , tramp-default-remote-shell )
310+ (tramp-remote-shell-login (" -l" ))
311+ (tramp-remote-shell-args (" -c" ))))
312+
256313 (tramp-set-completion-function
257314 tramp-docker-method
258315 `((tramp-container--completion-function
@@ -269,7 +326,25 @@ see its function help for a description of the format."
269326
270327 (tramp-set-completion-function
271328 tramp-toolbox-method
272- '((tramp-toolbox--completion-function " " ))))
329+ '((tramp-toolbox--completion-function " " )))
330+
331+ (tramp-set-completion-function
332+ tramp-flatpak-method
333+ '((tramp-flatpak--completion-function " " )))
334+
335+ ; ; Default connection-local variables for Tramp.
336+
337+ (defconst tramp-container-connection-local-default-flatpak-variables
338+ `((tramp-remote-path . ,(cons " /app/bin" tramp-remote-path)))
339+ " Default connection-local variables for remote flatpak connections." )
340+
341+ (connection-local-set-profile-variables
342+ 'tramp-container-connection-local-default-flatpak-profile
343+ tramp-container-connection-local-default-flatpak-variables)
344+
345+ (connection-local-set-profiles
346+ `(:application tramp :protocol , tramp-flatpak-method )
347+ 'tramp-container-connection-local-default-flatpak-profile ))
273348
274349(add-hook 'tramp-unload-hook
275350 (lambda ()
0 commit comments