@end lisp
@var{proxy} can take patterns @code{%h} or @code{%u} for @var{host} or
-@var{user} respectively.
+@var{user} respectively. Ports or domains, if they are part of
+a hop file name, are not expanded by those patterns.
To login as @samp{root} on remote hosts in the domain
@samp{your.domain}, but login as @samp{root} is disabled for non-local
(when (bound-and-true-p tramp-archive-enabled)
(tramp-archive-cleanup-hash))
+ ;; Remove ad-hoc proxies.
+ (let ((proxies tramp-default-proxies-alist))
+ (while proxies
+ (if (ignore-errors
+ (get-text-property 0 'tramp-ad-hoc (nth 2 (car proxies))))
+ (setq tramp-default-proxies-alist
+ (delete (car proxies) tramp-default-proxies-alist)
+ proxies tramp-default-proxies-alist)
+ (setq proxies (cdr proxies)))))
+ (when (and tramp-default-proxies-alist tramp-save-ad-hoc-proxies)
+ (customize-save-variable
+ 'tramp-default-proxies-alist tramp-default-proxies-alist))
+
;; Remove buffers.
(dolist (name (tramp-list-tramp-buffers))
(when (bufferp (get-buffer name)) (kill-buffer name))))
;; Ad-hoc proxy definitions.
(dolist (proxy (reverse (split-string hops tramp-postfix-hop-regexp 'omit)))
- (let ((user (tramp-file-name-user item))
- (host (tramp-file-name-host item))
+ (let ((user-domain (tramp-file-name-user-domain item))
+ (host-port (tramp-file-name-host-port item))
(proxy (concat
tramp-prefix-format proxy tramp-postfix-host-format)))
(tramp-message
vec 5 "Add proxy (\"%s\" \"%s\" \"%s\")"
- (and (stringp host) (regexp-quote host))
- (and (stringp user) (regexp-quote user))
+ (and (stringp host-port) (regexp-quote host-port))
+ (and (stringp user-domain) (regexp-quote user-domain))
proxy)
;; Add the hop.
(add-to-list
'tramp-default-proxies-alist
- (list (and (stringp host) (regexp-quote host))
- (and (stringp user) (regexp-quote user))
- proxy))
+ (list (and (stringp host-port) (regexp-quote host-port))
+ (and (stringp user-domain) (regexp-quote user-domain))
+ (propertize proxy 'tramp-ad-hoc t)))
(setq item (tramp-dissect-file-name proxy))))
;; Save the new value.
(when (and hops tramp-save-ad-hoc-proxies)
(when (and
;; Host.
(string-match (or (eval (nth 0 item)) "")
- (or (tramp-file-name-host (car target-alist)) ""))
+ (or (tramp-file-name-host-port (car target-alist))
+ ""))
;; User.
(string-match (or (eval (nth 1 item)) "")
- (or (tramp-file-name-user (car target-alist)) "")))
+ (or (tramp-file-name-user-domain (car target-alist))
+ "")))
(if (null proxy)
;; No more hops needed.
(setq choices nil)
This is an alist of items (HOST USER PROXY). The first matching
item specifies the proxy to be passed for a file name located on
a remote target matching USER@HOST. HOST and USER are regular
-expressions. PROXY must be a Tramp filename without a localname
-part. Method and user name on PROXY are optional, which is
-interpreted with the default values. PROXY can contain the
-patterns %h and %u, which are replaced by the strings matching
-HOST or USER, respectively.
+expressions, which could also cover a domain (USER%DOMAIN) or
+port (HOST#PORT). PROXY must be a Tramp filename without a
+localname part. Method and user name on PROXY are optional,
+which is interpreted with the default values.
+
+PROXY can contain the patterns %h and %u, which are replaced by
+the strings matching HOST or USER (without DOMAIN and PORT parts),
+respectively.
+
+If an entry is added while parsing ad-hoc hop definitions, PROXY
+carries the non-nil text property `tramp-ad-hoc'.
HOST, USER or PROXY could also be Lisp forms, which will be
evaluated. The result must be a string or nil, which is
(file-remote-p
(concat
"/method1:%u@%h"
- "|method2:%u@%h"
- "|method3:user3@host3:/path/to/file"))
- (format "/%s:%s@%s|%s:%s@%s|%s:%s@%s:"
- "method1" "user3" "host3"
- "method2" "user3" "host3"
- "method3" "user3" "host3")))))
+ "|method2:user2@host2"
+ "|method3:%u@%h"
+ "|method4:user4%domain4@host4#1234:/path/to/file"))
+ (format "/%s:%s@%s|%s:%s@%s|%s:%s@%s|%s:%s@%s:"
+ "method1" "user2" "host2"
+ "method2" "user2" "host2"
+ "method3" "user4" "host4"
+ "method4" "user4%domain4" "host4#1234")))))
(ert-deftest tramp-test02-file-name-dissect-simplified ()
"Check simplified file name components."
(file-remote-p
(concat
"/%u@%h"
+ "|user2@host2"
"|%u@%h"
- "|user3@host3:/path/to/file"))
- (format "/%s@%s|%s@%s|%s@%s:"
- "user3" "host3"
- "user3" "host3"
- "user3" "host3"))))
+ "|user4%domain4@host4#1234:/path/to/file"))
+ (format "/%s@%s|%s@%s|%s@%s|%s@%s:"
+ "user2" "host2"
+ "user2" "host2"
+ "user4" "host4"
+ "user4%domain4" "host4#1234"))))
;; Exit.
(tramp-change-syntax syntax))))
(file-remote-p
(concat
"/[method1/%u@%h"
- "|method2/%u@%h"
- "|method3/user3@host3]/path/to/file"))
- (format "/[%s/%s@%s|%s/%s@%s|%s/%s@%s]"
- "method1" "user3" "host3"
- "method2" "user3" "host3"
- "method3" "user3" "host3"))))
+ "|method2/user2@host2"
+ "|method3/%u@%h"
+ "|method4/user4%domain4@host4#1234]/path/to/file"))
+ (format "/[%s/%s@%s|%s/%s@%s|%s/%s@%s|%s/%s@%s]"
+ "method1" "user2" "host2"
+ "method2" "user2" "host2"
+ "method3" "user4" "host4"
+ "method4" "user4%domain4" "host4#1234"))))
;; Exit.
(tramp-change-syntax syntax))))