tramp-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Tramp mosh method


From: Ted Zlatanov
Subject: Re: Tramp mosh method
Date: Tue, 18 Dec 2012 09:15:21 -0500
User-agent: Gnus/5.130006 (Ma Gnus v0.6) Emacs/24.3.50 (gnu/linux)

I started on the code but can't figure out how to fool mosh-server into
thinking it has a TTY.  It still exits if the terminal height is 0.

I added a tramp-process-environment parameter which sets *additional*
environment parameters in the Tramp session.  I don't think the existing
tramp*env parameters do what I need.

I am attaching my work in progress, which hard-codes a mosh session to
one of my hosts (wd01).  I tried /usr/bin/script and other tricks but
just can't get mosh-server to believe the terminal is valid.  I would
really like to avoid having to make a source patch against mosh to make
it usable over Tramp, so any ideas are welcome.

Ted

=== modified file 'lisp/net/tramp-sh.el'
--- lisp/net/tramp-sh.el        2012-12-17 14:38:07 +0000
+++ lisp/net/tramp-sh.el        2012-12-18 14:10:16 +0000
@@ -85,6 +85,10 @@
 (defconst tramp-initial-end-of-output "#$ "
   "Prompt when establishing a connection.")
 
+;;;###tramp-autoload
+(defconst tramp-mosh-method "mosh"
+  "When this method name is used, forward all calls to mosh.")
+
 ;; Initialize `tramp-methods' with the supported methods.
 ;;;###tramp-autoload
 (add-to-list 'tramp-methods
@@ -406,6 +410,34 @@
     (tramp-copy-program         "fcp")
     (tramp-copy-args            (("-p" "%k")))
     (tramp-copy-keep-date       t)))
+;;;###tramp-autoload
+(add-to-list 'tramp-methods
+  `(,tramp-mosh-method
+    (tramp-login-program        "/usr/bin/script")
+    (tramp-login-args           (("-c" "'mosh wd01'") ("/dev/null") ("%h")))
+    (tramp-remote-shell         "/bin/sh")
+    (tramp-remote-shell-args    ("-c"))
+    (tramp-copy-keep-date       t)
+    (tramp-copy-recursive       t)
+    (tramp-gw-args              (("-o" "GlobalKnownHostsFile=/dev/null")
+                                 ("-o" "UserKnownHostsFile=/dev/null")
+                                 ("-o" "StrictHostKeyChecking=no")))
+    (tramp-process-filter       'tramp-mosh-process-filter)
+    (tramp-process-environment  (("LC_ALL" "en_US.UTF-8")
+                                 ("TERM" "linux")))
+    (tramp-default-port         22)))
+
+;; It must be a `defsubst' in order to push the whole code into
+;; tramp-loaddefs.el.  Otherwise, there would be recursive autoloading.
+;;;###tramp-autoload
+(defsubst tramp-mosh-file-name-p (filename)
+  "Check if it's a filename that should be handled with mosh."
+  (string= (tramp-file-name-method (tramp-dissect-file-name filename))
+          tramp-mosh-method))
+
+;;;###tramp-autoload
+(add-to-list 'tramp-foreign-file-name-handler-alist
+             (cons 'tramp-mosh-file-name-p 'tramp-sh-file-name-handler))
 
 ;;;###tramp-autoload
 (add-to-list 'tramp-default-method-alist
@@ -3903,6 +3935,7 @@
 
   (let ((env (copy-sequence tramp-remote-process-environment))
        unset item)
+
     (while env
       (setq item (tramp-compat-split-string (car env) "="))
       (setcdr item (mapconcat 'identity (cdr item) "="))
@@ -4396,6 +4429,15 @@
              (setenv "LC_ALL" "C")
              (setenv "PROMPT_COMMAND")
              (setenv "PS1" tramp-initial-end-of-output)
+
+              (let ((env (tramp-get-method-parameter
+                          (tramp-file-name-method vec)
+                          'tramp-process-environment))
+                    e)
+                (while (setq e (pop env))
+                  (message "e=%s" e)
+                  (apply 'setenv e)))
+
              (let* ((target-alist (tramp-compute-multi-hops vec))
                     (process-connection-type tramp-process-connection-type)
                     (process-adaptive-read-buffering nil)

=== modified file 'lisp/net/tramp.el'
--- lisp/net/tramp.el   2012-12-18 13:37:06 +0000
+++ lisp/net/tramp.el   2012-12-18 14:00:54 +0000
@@ -3092,6 +3092,7 @@
        (erase-buffer)))
 
     (if (and (not current-buffer-p) (integerp asynchronous))
+
        (prog1
            ;; Run the process.
            (setq p (apply 'start-file-process "*Async Shell*" buffer args))
@@ -3100,7 +3101,25 @@
          (setq mode-line-process '(":%s"))
          (shell-mode)
          (set-process-sentinel p 'shell-command-sentinel)
-         (set-process-filter p 'comint-output-filter))
+
+          ;; maybe set the process filter to tramp-process-filter
+          ;; (wrapped in a check to ensure we don't overwrite an
+          ;; existing output filter)
+          (with-current-buffer output-buffer
+            (unless (process-filter (current-buffer))
+              (let ((filter
+                     (tramp-get-method-parameter
+                      (tramp-file-name-method
+                       (tramp-dissect-file-name default-directory))
+                      'tramp-process-filter)))
+                (when filter
+                  (set-process-filter p filter)))))
+
+          ;; maybe set the process filter to comint-output-filter
+          ;; (wrapped in a check to ensure we don't overwrite an
+          ;; existing output filter)
+          (unless (process-filter (current-buffer))
+            (set-process-filter p 'comint-output-filter)))
 
       (prog1
          ;; Run the process.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]