如何让 Emacs 使用我的 .bashrc 文件? [英] How to make Emacs use my .bashrc file?
问题描述
我需要在 Emacs 中使用我的 $PATH
来运行一些命令.我怎样才能让 Emacs 使用它?我从 Ubuntu 存储库安装了 Emacs.
I need to use my $PATH
in Emacs to run some commands. How can I make Emacs use it? I installed Emacs from Ubuntu repositories.
推荐答案
这里有一个技巧 我使用 来确保我的 GUI Emacs 总是看到与我在 shell 中看到的相同的 $PATH
:
Here's a trick I use to ensure my GUI Emacs always sees the same $PATH
that I get inside a shell:
(defun set-exec-path-from-shell-PATH ()
(let ((path-from-shell (replace-regexp-in-string
"[
]*$"
""
(shell-command-to-string "$SHELL --login -i -c 'echo $PATH'"))))
(setenv "PATH" path-from-shell)
(setq eshell-path-env path-from-shell) ; for eshell users
(setq exec-path (split-string path-from-shell path-separator))))
(when window-system (set-exec-path-from-shell-PATH))
特别是在 OS X 上,图形化的 Emacs 不会获取用户 shell 对 $PATH
的定义,所以这个技巧在那个平台上对我有帮助.
Specifically, on OS X, a graphical Emacs will not pick up the user's shell's definition of $PATH
, so this trick helps me on that platform.
更新:此代码现已发布为名为 exec-的 elisp 库path-from-shell 和可安装包在 MELPA 中可用.
Update: this code has now been published as an elisp library called exec-path-from-shell and installable packages are available in MELPA.
这篇关于如何让 Emacs 使用我的 .bashrc 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!