Subject: Re: bug#57370: 28.1; eshell/addpath does not work when called noninteractively

From: Jim Porter <[email-masked]>
Date: Tue, 23 Aug 2022 17:16:33 -0700

On 8/23/2022 1:36 PM, Colton Lewis via Bug reports for GNU Emacs, the 
Swiss army knife of text editors wrote:
> Discovered this trying to add a path from my init file and I just could
> not make it work.
> 
> 1. Create an executable script ~/test-bin/test.sh
> 2. emacs -Q
> 3. Eval the elisp snippet `(require 'eshell) (eshell/addpath "~/test-bin")`
> 4. Start eshell
> 5. test.sh
> 6. Observe command not found error
> 
> Substituting `(eshell/addpath (file-truename "~/test-bin"))` gives the same
> problem.
> 
> This should have the same effect as starting eshell immediately and
> executing `addpath ~/test-bin`, which has the expected result.

I can't speak to the other issues you mentioned in this bug, but I 
wouldn't expect calls to any 'eshell/FOO' function to work outside of an 
Eshell prompt. Many of them assume the presence of various 
local/internal Eshell variables, so they wouldn't work if you called 
them from a different context.

To run some Eshell command, you could use 'eshell-command' or 
'eshell-command-result', as in:

   (eshell-command-result "echo hi there")
     => ("hi" "there")

However, that's not useful for calling 'eshell/addpath', since Eshell 
buffers have their own local 'process-environment'. You'd just be 
updating PATH in a temporary Eshell buffer, and then it'd go away 
immediately when the buffer is closed.

> The only workaround I've found is to modify PATH directly with setenv
> and getenv.

I think that's the best method. You could probably do it via 
'eshell-mode-hook' if you wanted to change the PATH only for Eshell.