"Tramp method name to use to connect to Flatpak sandboxes.")
;;;###tramp-autoload
-(defun tramp-container--completion-function (program)
+(defun tramp-container--completion-function (method)
"List running containers available for connection.
-PROGRAM is the program to be run for \"ps\", either
-`tramp-docker-program' or `tramp-podman-program'.
+METHOD is the Tramp method to be used for \"ps\", either
+`tramp-docker-method' or `tramp-podman-method'.
This function is used by `tramp-set-completion-function', please
see its function help for a description of the format."
- ;; Set the default-directory to the directory of the last hop
- ;; of a multi-hop path so that we can run the container program
- ;; from there. If this is not a multi-hop path, run from the local
- ;; temp file directory.
- (when-let ((default-directory (or (and tramp-completion-remote-containers tramp--last-hop-directory)
- tramp-compat-temporary-file-directory))
- (raw-list (shell-command-to-string
- (concat 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 (name) (list nil name)) (delq nil names))))
+ (let ((default-directory
+ (or (and tramp-completion-remote-containers tramp--last-hop-directory)
+ tramp-compat-temporary-file-directory))
+ (program (tramp-get-method-parameter
+ (make-tramp-file-name :method method) 'tramp-login-program))
+ non-essential)
+ ;; We don't use connection properties, because this information
+ ;; shouldn't be kept persistently.
+ (with-tramp-file-property
+ (when (tramp-tramp-file-p default-directory)
+ (tramp-dissect-file-name default-directory))
+ (concat "/" method ":") "user-host-completions"
+ (when-let ((raw-list
+ (shell-command-to-string
+ (concat 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 (name) (list nil name)) (delq nil names))))))
;;;###tramp-autoload
(defun tramp-kubernetes--completion-function (&rest _args)
(tramp-set-completion-function
tramp-docker-method
- `((tramp-container--completion-function
- ,tramp-docker-program)))
+ `((tramp-container--completion-function ,tramp-docker-method)))
(tramp-set-completion-function
tramp-podman-method
- `((tramp-container--completion-function
- ,tramp-podman-program)))
+ `((tramp-container--completion-function ,tramp-podman-method)))
(tramp-set-completion-function
tramp-kubernetes-method
(defvar tramp-file-name-regexp)
(defvar tramp-completion-method-regexp)
(defvar tramp-completion-file-name-regexp)
-(defvar tramp--last-hop-directory nil
- "Tracks the directory from which to run container executable programs.")
;; Reload `tramp-compat' when we reload `tramp-autoloads' of the GNU
;; ELPA package.
tramp-dns-sd-service-regexp (nth 1 (car v))))
;; Method.
((string-equal method (nth 1 (car v))))
- ;; FIXME: for now do not check local existence of file
- ;; to allow allow arbitrary container program executable
- ;; name for container completion on remote systems.
- (t t)))
+ ;; Configuration file or empty string.
+ (t (file-exists-p (nth 1 (car v))))))
(setq r (delete (car v) r)))
(setq v (cdr v)))
(tramp-run-real-handler #'file-exists-p (list filename))))
+(defvar tramp--last-hop-directory nil
+ "Tracks the directory from which to run login programs.")
+
;; Method, host name and user name completion.
;; `tramp-completion-dissect-file-name' returns a list of
;; `tramp-file-name' structures. For all of them we return possible
;; Possible completion structures.
(dolist (elt (tramp-completion-dissect-file-name fullname))
- (let* ((method (tramp-file-name-method elt))
+ (let* ((method (tramp-file-name-method elt))
(user (tramp-file-name-user elt))
(host (tramp-file-name-host elt))
(localname (tramp-file-name-localname elt))
(if (or user host)
- ;; Method dependent user / host combinations.
- (progn
+ ;; Method dependent user / host combinations.
+ (progn
(mapc
(lambda (x)
(setq all-user-hosts
(tramp-get-completion-function m))
(setq result
- (append result
- (mapcar
- (lambda (x)
+ (append result
+ (mapcar
+ (lambda (x)
(tramp-get-completion-user-host
method user host (nth 0 x) (nth 1 x)))
- (delq nil all-user-hosts)))))
+ (delq nil all-user-hosts)))))
;; Possible methods.
(setq result
;; This function returns all possible method completions, adding the
;; trailing method delimiter.
-(defun tramp-get-completion-methods (partial-method hop)
+(defun tramp-get-completion-methods (partial-method multi-hop)
"Return all method completions for PARTIAL-METHOD.
-If HOP is non-nil, return only multi-hop capable methods."
+If MULTI-HOP is non-nil, return only multi-hop capable methods."
(mapcar
(lambda (method)
(and method (string-prefix-p (or partial-method "") method)
- (or (not hop)
+ (or (not multi-hop)
(tramp-multi-hop-p (make-tramp-file-name :method method)))
(tramp-completion-make-tramp-file-name method nil nil nil)))
(mapcar #'car tramp-methods)))
(defcustom tramp-completion-remote-containers nil
"Whether container hosts in multi-hop paths should be queried for completions."
+ :version "30.1"
:type 'boolean)
(defcustom tramp-completion-use-auth-sources auth-source-do-cache
(defun tramp-multi-hop-p (vec)
"Whether the method of VEC is capable of multi-hops."
- (and (tramp-sh-file-name-handler-p vec)
- (not (tramp-get-method-parameter vec 'tramp-copy-program))))
+ (let ((tramp-verbose 0))
+ (and (tramp-sh-file-name-handler-p vec)
+ (not (tramp-get-method-parameter vec 'tramp-copy-program)))))
(defun tramp-add-hops (vec)
"Add ad-hoc proxy definitions to `tramp-default-proxies-alist'."