6
  1. How can I configure eshell to be able to run programs from directories in PATH env variable?

  2. How can I add additional custom directories to the list?

I use Emacs 24.3.1.

7

The Emacs equivalent of the PATH environment variable is exec-path, which is a list instead of a colon-separated string.

Its content it initialized with the value of PATH, so supposedly it should be all transparent. But if this happens not to contain what you want (typically when Emacs is not run from a shell, but from a Desktop Environment), you might find this package useful: exec-path-from-shell. Install it from Marmalade or MELPA using

M-x package-install exec-path-from-shell RET
  • 2
    If Emacs doesn't get your custom PATH when you start it from your desktop environment, it's because you didn't set your custom PATH in the right place. Set environment variables in .profile, not in .bashrc. – Gilles Sep 29 '14 at 18:21
  • Copying export PATH=... to ~/.profiledid not work for me. I still see PATH set to value created by desktop environment. – whysoserious Sep 29 '14 at 20:45
  • 1
    @Gilles That's good advice generally, but doesn't help on OS X, where the user's shell is not involved in starting GUI apps such as Emacs.app. – sanityinc Sep 30 '14 at 13:03
  • @Gilles Adding things to $PATH does not make eshell see them, at least not on my system. – Zelphir Kaltstahl Feb 11 '18 at 18:38
5

You can configure TRAMP to respect the PATH variable on the remote machine (for remote eshell sessions) by adding 'tramp-own-remote-path to the list 'tramp-remote-path:

(add-to-list 'tramp-remote-path 'tramp-own-remote-path)

By default, eshell will not adopt the remote PATH settings.

  • I don't see that this works. Perhaps, that's because I set and export a custom PATH in ~/.bash_profile (contrary to ~/.profile) which I have seen in some docs concerning these tramp-* vars... – imz -- Ivan Zakharyaschev Jan 26 '15 at 20:03
  • I've asked specifically the question about eshell+tramp: emacs.stackexchange.com/q/7673/5165 If you have ideas why this might not work for me, I'd be grateful if you write about it there. – imz -- Ivan Zakharyaschev Jan 26 '15 at 20:15
3

For a clear answer to part 2 (How can I add additional custom directories to the list?):

You can use the following elisp to customize your exec-path variable to include any additional directories

(add-to-list 'exec-path "/custom/directory/path")

Use case

Although the other answers specify how to add to your $PATH (%PATH% on Windows) there are cases where this is not really a solution, particularly in a Windows environment.

Suppose you have Cygwin installed and do not want to include c:\cygwin\bin in %PATH% (user or system) because it will overwrite certain DOS built-in commands (Find) and could break any scripts that call them.

Adding it directly to exec-path within Emacs on startup can ensure you get full access to those tools within the editor, without installing Cygwin Emacs.

2

To answer to your first question: Eshell is already able to run programs in PATH. Here's an example:

Welcome to the Emacs shell

~ $ env-info

manuel@bebop

OS: LinuxBBQ Haggis
Uptime: 0d 4h 9m
Shell: /bin/zsh
WM: ratpoison
Disk: 37G / 257G
Mem: 1180M / 4042M
Kernel: Linux 3.16-2-686-pae i686
CPU: Intel(R) Core(TM)2 Duo CPU     T6400  @ 2.00GHz

~ $ which env-info
/home/manuel/bin/env-info
~ $ echo $PATH | grep bin
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/manuel/bin
0

For an even clearer answer to part 2 (How can I add additional custom directories to the list?): [this adds the current directory]

addpath (pwd)

or to add something relative to your current directory

addpath $(pwd)subdir1/subdir2

https://www.gnu.org/software/emacs/manual/html_mono/eshell.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.