47
47
; ; C-x C-f /kubernetes:POD:/path/to/file
48
48
; ;
49
49
; ; 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.
53
53
; ;
54
54
; ; Completion for POD and accessing it operate in the current
55
55
; ; namespace, use this command to change it:
58
58
; ;
59
59
; ;
60
60
; ;
61
- ; ; Open a file on an existing toolbox container via Toolbox :
61
+ ; ; Open a file on an existing Toolbox container:
62
62
; ;
63
63
; ; C-x C-f /toolbox:CONTAINER:/path/to/file
64
64
; ;
67
67
; ;
68
68
; ; If the container is not running, it is started. If no container is
69
69
; ; 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.
70
80
71
81
; ;; Code:
72
82
104
114
:type '(choice (const " toolbox" )
105
115
(string )))
106
116
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
+
107
125
; ;;###tramp-autoload
108
126
(defconst tramp-docker-method " docker"
109
127
" Tramp method name to use to connect to Docker containers." )
120
138
(defconst tramp-toolbox-method " toolbox"
121
139
" Tramp method name to use to connect to Toolbox containers." )
122
140
141
+ ; ;;###tramp-autoload
142
+ (defconst tramp-flatpak-method " flatpak"
143
+ " Tramp method name to use to connect to Flatpak sandboxes." )
144
+
123
145
; ;;###tramp-autoload
124
146
(defun tramp-container--completion-function (program )
125
147
" List running containers available for connection.
@@ -195,6 +217,30 @@ see its function help for a description of the format."
195
217
lines)))
196
218
(mapcar (lambda (name ) (list nil name)) (delq nil names))))
197
219
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
+
198
244
; ;;###tramp-autoload
199
245
(defvar tramp-default-remote-shell ) ; ; Silence byte compiler.
200
246
@@ -253,6 +299,17 @@ see its function help for a description of the format."
253
299
254
300
(add-to-list 'tramp-default-host-alist `(, tramp-toolbox-method nil " " ))
255
301
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
+
256
313
(tramp-set-completion-function
257
314
tramp-docker-method
258
315
`((tramp-container--completion-function
@@ -269,7 +326,25 @@ see its function help for a description of the format."
269
326
270
327
(tramp-set-completion-function
271
328
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 ))
273
348
274
349
(add-hook 'tramp-unload-hook
275
350
(lambda ()
0 commit comments