diff options
author | Michael Albinus <michael.albinus@gmx.de> | 2024-05-08 13:44:15 +0200 |
---|---|---|
committer | Michael Albinus <michael.albinus@gmx.de> | 2024-05-08 13:44:15 +0200 |
commit | 339b8349f436b3738cfa02b236e05c3da4c5a8a5 (patch) | |
tree | 213fe7fefebd087c685bc7cf3c2c1171a4ef094b /lisp/net | |
parent | e020f4e9ce5d98438033fea098d943c311b0fa3d (diff) | |
download | emacs-339b8349f436b3738cfa02b236e05c3da4c5a8a5.tar.gz |
More Tramp optional methods
* doc/misc/tramp.texi (Inline methods) <krlogin, ksu>:
(External methods) <fcp, nc>: These are optional methods.
* etc/NEWS: Mention more optional Tramp methods.
* lisp/net/tramp-androidsu.el (tramp-enable-androidsu-method):
Use proper regexp for `tramp-default-user-alist'.
* lisp/net/tramp-sh.el (tramp-enable-nc-method)
(tramp-enable-ksu-method, tramp-enable-krlogin-method)
(tramp-enable-fcp-method): New defuns. Move respective
configurations there.
* lisp/net/tramp.el (tramp-enable-method): Implement completion
for interactive use.
* test/lisp/net/tramp-tests.el (tramp-test03-file-name-defaults)
(tramp-test03-file-name-host-rules): Extend tests.
Diffstat (limited to 'lisp/net')
-rw-r--r-- | lisp/net/tramp-androidsu.el | 3 | ||||
-rw-r--r-- | lisp/net/tramp-sh.el | 133 | ||||
-rw-r--r-- | lisp/net/tramp.el | 22 |
3 files changed, 105 insertions, 53 deletions
diff --git a/lisp/net/tramp-androidsu.el b/lisp/net/tramp-androidsu.el index 09dcd4d7bed..953f75ad9f3 100644 --- a/lisp/net/tramp-androidsu.el +++ b/lisp/net/tramp-androidsu.el @@ -91,7 +91,8 @@ may edit files belonging to any and all applications." (tramp-shell-name ,tramp-androidsu-local-shell-name))) (add-to-list 'tramp-default-user-alist - `(,tramp-androidsu-method nil ,tramp-root-id-string))) + `(,(rx bos (literal tramp-androidsu-method) eos) + nil ,tramp-root-id-string))) ;;;###tramp-autoload (tramp--with-startup diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index 60478707c2d..408e1611632 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el @@ -273,22 +273,6 @@ The string is used in `tramp-methods'.") (tramp-remote-shell-login ("-l")) (tramp-remote-shell-args ("-c")))) (add-to-list 'tramp-methods - `("nc" - (tramp-login-program "telnet") - (tramp-login-args (("%h") ("%p") ("%n"))) - (tramp-remote-shell ,tramp-default-remote-shell) - (tramp-remote-shell-login ("-l")) - (tramp-remote-shell-args ("-c")) - (tramp-copy-program "nc") - ;; We use "-v" for better error tracking. - (tramp-copy-args (("-w" "1") ("-v") ("%h") ("%r"))) - (tramp-copy-file-name (("%f"))) - (tramp-remote-copy-program "nc") - ;; We use "-p" as required for newer busyboxes. For older - ;; busybox/nc versions, the value must be (("-l") ("%r")). This - ;; can be achieved by tweaking `tramp-connection-properties'. - (tramp-remote-copy-args (("-l") ("-p" "%r") ("%n"))))) - (add-to-list 'tramp-methods `("su" (tramp-login-program "su") (tramp-login-args (("-") ("%u"))) @@ -329,21 +313,6 @@ The string is used in `tramp-methods'.") (tramp-session-timeout 300) (tramp-password-previous-hop t))) (add-to-list 'tramp-methods - `("ksu" - (tramp-login-program "ksu") - (tramp-login-args (("%u") ("-q"))) - (tramp-remote-shell ,tramp-default-remote-shell) - (tramp-remote-shell-login ("-l")) - (tramp-remote-shell-args ("-c")) - (tramp-connection-timeout 10))) - (add-to-list 'tramp-methods - `("krlogin" - (tramp-login-program "krlogin") - (tramp-login-args (("%h") ("-l" "%u") ("-x"))) - (tramp-remote-shell ,tramp-default-remote-shell) - (tramp-remote-shell-login ("-l")) - (tramp-remote-shell-args ("-c")))) - (add-to-list 'tramp-methods `("plink" (tramp-login-program "plink") (tramp-login-args (("-l" "%u") ("-P" "%p") ("-ssh") ("%c") @@ -403,30 +372,18 @@ The string is used in `tramp-methods'.") (tramp-copy-args (("-l" "%u") ("-P" "%p") ("-sftp") ("-p" "%k"))) (tramp-copy-keep-date t))) - (add-to-list 'tramp-methods - `("fcp" - (tramp-login-program "fsh") - (tramp-login-args (("%h") ("-l" "%u") ("sh" "-i"))) - (tramp-remote-shell ,tramp-default-remote-shell) - (tramp-remote-shell-login ("-l")) - (tramp-remote-shell-args ("-i") ("-c")) - (tramp-copy-program "fcp") - (tramp-copy-args (("-p" "%k"))) - (tramp-copy-keep-date t))) (add-to-list 'tramp-default-method-alist `(,tramp-local-host-regexp ,(rx bos (literal tramp-root-id-string) eos) "su")) (add-to-list 'tramp-default-user-alist - `(,(rx bos (| "su" "sudo" "doas" "ksu") eos) + `(,(rx bos (| "su" "sudo" "doas") eos) nil ,tramp-root-id-string)) ;; Do not add "ssh" based methods, otherwise ~/.ssh/config would be ignored. ;; Do not add "plink" based methods, they ask interactively for the user. (add-to-list 'tramp-default-user-alist - `(,(rx bos - (| "rcp" "remcp" "rsh" "telnet" "nc" "krlogin" "fcp") - eos) + `(,(rx bos (| "rcp" "remcp" "rsh" "telnet") eos) nil ,(user-login-name)))) (defconst tramp-default-copy-file-name '(("%u" "@") ("%h" ":") ("%f")) @@ -508,20 +465,94 @@ The string is used in `tramp-methods'.") (tramp-set-completion-function "sshx" tramp-completion-function-alist-ssh) (tramp-set-completion-function "telnet" tramp-completion-function-alist-telnet) - (tramp-set-completion-function "nc" tramp-completion-function-alist-telnet) (tramp-set-completion-function "su" tramp-completion-function-alist-su) (tramp-set-completion-function "sudo" tramp-completion-function-alist-su) (tramp-set-completion-function "doas" tramp-completion-function-alist-su) - (tramp-set-completion-function "ksu" tramp-completion-function-alist-su) (tramp-set-completion-function "sg" tramp-completion-function-alist-sg) - (tramp-set-completion-function - "krlogin" tramp-completion-function-alist-rsh) (tramp-set-completion-function "plink" tramp-completion-function-alist-ssh) (tramp-set-completion-function "plinkx" tramp-completion-function-alist-putty) (tramp-set-completion-function "pscp" tramp-completion-function-alist-ssh) - (tramp-set-completion-function "psftp" tramp-completion-function-alist-ssh) - (tramp-set-completion-function "fcp" tramp-completion-function-alist-ssh)) + (tramp-set-completion-function "psftp" tramp-completion-function-alist-ssh)) + +;;;###tramp-autoload +(defun tramp-enable-nc-method () + "Enable \"ksu\" method." + (add-to-list 'tramp-methods + `("nc" + (tramp-login-program "telnet") + (tramp-login-args (("%h") ("%p") ("%n"))) + (tramp-remote-shell ,tramp-default-remote-shell) + (tramp-remote-shell-login ("-l")) + (tramp-remote-shell-args ("-c")) + (tramp-copy-program "nc") + ;; We use "-v" for better error tracking. + (tramp-copy-args (("-w" "1") ("-v") ("%h") ("%r"))) + (tramp-copy-file-name (("%f"))) + (tramp-remote-copy-program "nc") + ;; We use "-p" as required for newer busyboxes. For + ;; older busybox/nc versions, the value must be + ;; (("-l") ("%r")). This can be achieved by tweaking + ;; `tramp-connection-properties'. + (tramp-remote-copy-args (("-l") ("-p" "%r") ("%n"))))) + + (add-to-list 'tramp-default-user-alist + `(,(rx bos "nc" eos) nil ,(user-login-name))) + + (tramp-set-completion-function "nc" tramp-completion-function-alist-telnet)) + +;;;###tramp-autoload +(defun tramp-enable-ksu-method () + "Enable \"ksu\" method." + (add-to-list 'tramp-methods + `("ksu" + (tramp-login-program "ksu") + (tramp-login-args (("%u") ("-q"))) + (tramp-remote-shell ,tramp-default-remote-shell) + (tramp-remote-shell-login ("-l")) + (tramp-remote-shell-args ("-c")) + (tramp-connection-timeout 10))) + + (add-to-list 'tramp-default-user-alist + `(,(rx bos "ksu" eos) nil ,tramp-root-id-string)) + + (tramp-set-completion-function "ksu" tramp-completion-function-alist-su)) + +;;;###tramp-autoload +(defun tramp-enable-krlogin-method () + "Enable \"krlogin\" method." + (add-to-list 'tramp-methods + `("krlogin" + (tramp-login-program "krlogin") + (tramp-login-args (("%h") ("-l" "%u") ("-x"))) + (tramp-remote-shell ,tramp-default-remote-shell) + (tramp-remote-shell-login ("-l")) + (tramp-remote-shell-args ("-c")))) + + (add-to-list 'tramp-default-user-alist + `(,(rx bos "krlogin" eos) nil ,(user-login-name))) + + (tramp-set-completion-function + "krlogin" tramp-completion-function-alist-rsh)) + +;;;###tramp-autoload +(defun tramp-enable-fcp-method () + "Enable \"fcp\" method." + (add-to-list 'tramp-methods + `("fcp" + (tramp-login-program "fsh") + (tramp-login-args (("%h") ("-l" "%u") ("sh" "-i"))) + (tramp-remote-shell ,tramp-default-remote-shell) + (tramp-remote-shell-login ("-l")) + (tramp-remote-shell-args ("-i") ("-c")) + (tramp-copy-program "fcp") + (tramp-copy-args (("-p" "%k"))) + (tramp-copy-keep-date t))) + + (add-to-list 'tramp-default-user-alist + `(,(rx bos "fcp" eos) nil ,(user-login-name))) + + (tramp-set-completion-function "fcp" tramp-completion-function-alist-ssh)) (defcustom tramp-sh-extra-args `((,(rx (| bos "/") "bash" eos) . "-noediting -norc -noprofile") diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index f6d02847927..7d599377969 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -1462,7 +1462,27 @@ calling HANDLER.") (defun tramp-enable-method (method) "Enable optional METHOD if possible." - (interactive "Mmethod: ") + (interactive + (list + (completing-read + "method: " + (seq-keep + (lambda (x) + (when-let ((name (symbol-name x)) + ;; It must match `tramp-enable-METHOD-method'. + ((string-match + (rx "tramp-enable-" + (group (regexp tramp-method-regexp)) + "-method") + name)) + (method (match-string 1 name)) + ;; It must not be enabled yet. + ((not (assoc method tramp-methods)))) + method)) + ;; All method enabling functions. + (mapcar + #'intern (all-completions "tramp-enable-" obarray #'functionp)))))) + (when-let (((not (assoc method tramp-methods))) (fn (intern (format "tramp-enable-%s-method" method))) ((functionp fn))) |