tramp-devel
[Top][All Lists]
Advanced

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

Re: Tramp + eshell


From: Michael Albinus
Subject: Re: Tramp + eshell
Date: Fri, 29 Oct 2021 13:40:50 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

Daniel Kraus <daniel@kraus.my> writes:

> Hi!

Hi,

> It's like you said, when you "cd /" you're no longer on the remote server
> but on your local machine.
>
> I have this in my config to not "jump out":
>
>   (defun eshell/lcd (&optional directory)
>     "Like regular 'cd' but don't jump out of a tramp directory.
> When on a remote directory with tramp don't jump 'out' of the server.
> So if we're connected with sudo to 'remotehost'
> '$ lcd /etc' would go to '/sudo:remotehost:/etc' instead of just
> '/etc' on localhost."
>     (if (file-remote-p default-directory)
>         (with-parsed-tramp-file-name default-directory nil
>           (eshell/cd
>            (tramp-make-tramp-file-name
>             method user nil host nil (or directory "") hop)))
>       (eshell/cd directory)))
>
>
> Then you can "lcd /" and you would end up in "/plinkx:Eval:/".

Or

(defun eshell/lcd (&optional directory)
  "Like regular 'cd' but don't jump out of a tramp directory.
When on a remote directory with tramp don't jump 'out' of the server.
So if we're connected with sudo to 'remotehost'
'$ lcd /etc' would go to '/sudo:remotehost:/etc' instead of just
'/etc' on localhost."
  (setq directory (or directory "~/"))
  (unless (file-remote-p directory)
    (setq directory (concat (file-remote-p default-directory) directory)))
  (eshell/cd directory))

In general, I argue against using Tramp internal functions. Their API is
not guranteed to be kept. For example, tramp-make-tramp-file-name has
changed its argument list in Tramp 2.4.0 (Emacs 27.1), the old argument
list (which you use) is kept for backward compatibility. When Tramp
throws compatibility for Emacs 26, this backward compatibility might be
skipped.

> Cheers,
>   Daniel

Best regards, Michael.



reply via email to

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