all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Jim Porter <jporterbugs@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 70792@debbugs.gnu.org
Subject: bug#70792: 30.0.50; [PATCH] Add Eshell support for expanding absolute file names within the current remote connection
Date: Mon, 6 May 2024 11:13:20 -0700	[thread overview]
Message-ID: <fe51fb39-13c0-05a9-0204-daab292cf34f@gmail.com> (raw)
In-Reply-To: <86y18nb3ap.fsf@gnu.org>

On 5/6/2024 4:14 AM, Eli Zaretskii wrote:
> I don't understand how would this work conceptually.  Suppose I want
> to run a command on a remote host, but pipe the results into a command
> that runs locally -- how will Eshell know which file name to interpret
> relative to which directory, and how can the user indicate which is
> which unequivocally?

Thanks for taking a look. I'll try to explain this in more detail, since 
it's a fairly subtle interaction, especially if you don't use Tramp + 
Eshell heavily. (With the benefit of hindsight, we might have chosen not 
to handle remote access in Eshell the way it does, but it's now one of 
the big features users mention when they describe what they like about 
it. This patch is my best attempt at smoothing some of the existing 
rough edges here so that remote access in Eshell doesn't feel so 
capricious.)

Anyway...

File names are expanded according to the current working directory when 
you enter your command, so unless you explicitly type out the host in a 
file name, it's treated as belonging to the host associated with cwd. 
(If it helps, this is sort of like how "~" is expanded in regular 
shells. The shell expands it early on when parsing your input, so "sudo 
echo ~" outputs *your* homedir, not root's.)

Here are some examples with the new option enabled (note that "*" before 
a program name means "always execute the external program on the host"):

   ##### 1. Change to root
~ $ cd /sudo::
/sudo:root@host:~ # pwd; *pwd
/sudo:root@host:/root
/root

   ##### 2. Change to an absolute directory, stay as root
/sudo:root@host:~ # cd /etc; pwd; *pwd
/sudo:root@host:/etc
/etc

   ##### 3. Change to the home directory, stay as root
/sudo:root@host:~ # cd ~; pwd; *pwd
/sudo:root@host:/root
/root

   ##### 4. Write the expanded "~/foo.txt" to the *local* "~/bar.txt".
   ##### Using "/:" quoting lets you explicitly name a local file
/sudo:root@host:~ # *echo ~/foo.txt > /:~/bar.txt
/sudo:root@host:~ # cat bar.txt
/bin/cat: bar.txt: No such file or directory

   ##### 5. Change to the *local* home directory, stop being root
/sudo:root@host:~ # cd /:~; pwd; *pwd
/home/jim
/home/jim

   ##### 6. "bar.txt" ended up here
~ $ cat bar.txt
['-c', '/root/foo.txt']

In the last line above, note that the value we wrote to our file is just 
the local part. There's no Tramp remote host part here because Python 
(or other any other external program) wouldn't understand that syntax. 
Eshell strips off the remote part for you, unless you escape the 
argument, e.g. by surrounding it with quotes. (When doing this 
unexpanding, Eshell also makes sure that the remote host of the file 
name matches the host where the program will run.)

> IOW, I fear that this problem cannot be solved in principle in a
> shell-like application, and so trying to solve it will only cause us a
> terrible complexity mess.  What am I missing?

With this option *disabled* (the default), there are some problems that 
(in my opinion) make working with remote file names in Eshell even more 
complex. For example, suppose I'm on a remote host, and want to change 
to my home directory on that remote. There's not an easy way to do that:

   ##### 3b. Change to the home directory; stop being root(!)
/sudo:root@host:~ # cd ~; pwd; *pwd
/home/jim
/home/jim

Or suppose my cwd is /ssh:user@remote:/somedir. If I run "cat 
/etc/hosts", Eshell will print my local hosts file. But what if I run 
"cat -n /etc/hosts"? Eshell's "cat" implementation doesn't understand 
"-n", so it calls the "cat" on "remote". Now it prints the remote hosts 
file. You can only predict which hosts files you'll get if you know 
exactly which flags Eshell's "cat" implementation supports.





  reply	other threads:[~2024-05-06 18:13 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-05 20:58 bug#70792: 30.0.50; [PATCH] Add Eshell support for expanding absolute file names within the current remote connection Jim Porter
2024-05-06 11:14 ` Eli Zaretskii
2024-05-06 18:13   ` Jim Porter [this message]
2024-05-06 18:43     ` Eli Zaretskii
2024-05-06 20:05       ` Jim Porter
2024-05-07  2:01         ` Jim Porter
2024-05-07 11:55         ` Eli Zaretskii
2024-05-07 18:54           ` Jim Porter
2024-05-08 13:20             ` Eli Zaretskii
2024-05-08 16:13               ` Jim Porter
2024-05-08 18:32                 ` Eli Zaretskii
2024-05-08 18:57                   ` Jim Porter
2024-05-09 18:14                   ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-09 18:53                     ` Eli Zaretskii
2024-05-09 19:10                       ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-09 20:30                         ` Jim Porter
2024-05-09 22:15                           ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-09 22:28                             ` Jim Porter
2024-05-10  5:45                           ` Eli Zaretskii
2024-05-10 19:35                             ` Jim Porter
2024-05-13  7:39                               ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-16  2:12                                 ` Jim Porter
2024-05-08 18:17               ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-08 18:49                 ` Eli Zaretskii
2024-05-09 18:22                   ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-09 19:02                     ` Eli Zaretskii
2024-05-07  8:12       ` Michael Albinus via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-06 16:56 ` Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-06 17:59   ` Eli Zaretskii
2024-05-06 18:28   ` Jim Porter
2024-05-06 18:37     ` Jim Porter
2024-05-07  8:50     ` Sean Whitton via Bug reports for GNU Emacs, the Swiss army knife of text editors

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fe51fb39-13c0-05a9-0204-daab292cf34f@gmail.com \
    --to=jporterbugs@gmail.com \
    --cc=70792@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.