2011-10-20 20 views
9

/多用於爲我工作,現在它消失了,我很沮喪。如何使用Emacs tramp ssh到遠程主機並在臨時基礎上編輯另一個用戶的文件?

我想要做的是,在我的夢幻世界:

/myuser的@遠程主機:須藤:anotheruser:/一些/路徑/到/文件

...並有IDO模式工作。

這裏的關鍵是'myuser','remotehost'和'anotheruser'都是非常特殊的,我使用大量的遠程主機,通常與不同的用戶和sudo-ing到廣泛的不同的用戶。

我需要添加什麼以及如何在不重新加載emacs的情況下對其進行測試?

+0

你能更精確一點:你使用'tramp-completion-function-alist'嗎?你的配置是什麼?也許下面的帖子可能會幫助你:http://stackoverflow.com/questions/95631/open-a-file-with-su-sudo-inside-emacs – Renaud

+1

這個線程給出了完整的背景: http:// lists。 gnu.org/archive/html/tramp-devel/2011-10/msg00014.html –

回答

8

this commit開始,TRAMP再次支持ad-hoc多跳。

粗略地講,您可以使用這樣的:

/ssh:[email protected]|sudo:[email protected]:/some/file 

我沒有得到它與ido-mode可靠地工作呢,這是一種恥辱,但它總比沒有好很多! :-)

+2

包含在Emacs 24中,供任何人使用。另請參閱http://stackoverflow.com/a/16408592/324105 – phils

+0

證實了Emacs 24.3的這一功能,無需特殊配置。澄清一點:如果您的是在〜/ .ssh/config(與主機)中定義的別名,則在兩個地方使用您的本地別名 - 您不需要轉換爲sudo的真實主機名。你也可以用這個命令打開遠程目錄和eshell。 – mike

0

下面的代碼可能會有所幫助:

(defun find-file-as-root() 
    "Find a file as root." 
    (interactive) 
    (let* ((parsed (when (tramp-tramp-file-p default-directory) 
        (coerce (tramp-dissect-file-name default-directory) 
          'list))) 
      (default-directory 
      (if parsed 
       (apply 'tramp-make-tramp-file-name 
         (append '("sudo" "root") (cddr parsed))) 
       (tramp-make-tramp-file-name "sudo" "root" "localhost" 
              default-directory)))) 
     (call-interactively 'find-file))) 

我有它在我的.emacs文件,它似乎來自這裏:http://atomized.org/2011/01/toggle-between-root-non-root-in-emacs-with-tramp/

我還沒有廣泛使用,但它似乎像這是朝着正確方向邁出的一步。

相關問題