Getting Emacs to respect my default shell + option

2020-06-01 08:02发布

问题:

I'm trying to get my Emacs shell to mimic that of my standard terminal sessions. Basically I would like it to respect the same PATH as well as the command prompt.

So far I have a few issues:

  • PATH isn't found, below is the fix I'm using for that.
  • I'm getting ascii color codes all over the place with another fix I tried.

I have the following in my mwilliams.el file. The first few lines give me access to /usr/local/bin in M-x shell, which solves half the problem and the last few lines get me running with Zsh but my prompt is very screw.

(setenv "PATH" (concat (getenv "PATH") ":/usr/local/bin"))
(setq exec-path (append exec-path '("/usr/local/bin")))


(defun shell ()
  (interactive)
  (ansi-term "/bin/zsh"))

With the above I get the following all throughout when I M-x shell.

4m\342/236/234 

The modes being used are: (Term: char run yas)

As far as I can tell it's not respecting some of the ascii color codes in my Zsh theme. I am however seeing a few colors coming through; so it's half way there. My best guess is that I need it to respect my .zshrc which contains information about my theme and PATH.

I'm just getting my feet wet in Emacs and getting a solid shell is one of the last few things I need before I can start migrating my daily work (and everything else) over to Emacs.

I'm running Emacs 23.1 (9.0) in OSX Snow Leopard.

回答1:

I don't use zsh but I found this in the zsh FAQ and gave it a try. I got a colorful ls with no funky characters.

3.10: Why does zsh not work in an Emacs shell mode any more?

Read more: http://www.faqs.org/faqs/unix-faq/shell/zsh/#ixzz0TyTJsHMq

Another method is to put

#!/bin/sh 
TERM=emacs exec zsh

into a file ~/bin/eshell, then chmod +x ~/bin/eshell, and tell emacs to use that as the shell by adding

(setenv "ESHELL" (expand-file-name "~/bin/eshell"))

to ~/.emacs.



回答2:

For the path, there is the package exec-path-from-shell (OS X only).

It gets $MANPATH, $PATH and exec-path from the shell and sets them for emacs.