exec-path-from-shell

Make Emacs use the $PATH set up by the user's shell

  • 所有者: purcell/exec-path-from-shell
  • 平台:
  • 许可证: Other
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

Melpa Status
Melpa Stable Status

exec-path-from-shell

A GNU Emacs library to ensure environment variables inside Emacs look
the same as in the user's shell.

Motivation

Ever find that a command works in your shell, but not in Emacs?

This happens a lot on OS X, where an Emacs instance started from the GUI inherits a
default set of environment variables.

This library solves this problem by copying important environment
variables from the user's shell: it works by asking your shell to print out the
variables of interest, then copying them into the Emacs environment.

Compatibility

If the path printed by evaluating (getenv "SHELL") in Emacs points at bash
or zsh, this should work fine.

At a minimum, this package assumes that your shell is at least UNIX-y: if
(getenv "SHELL") evaluates to something like ".../cmdproxy.exe", this
package probably isn't for you.

Further, if you use a non-POSIX-standard shell such as tcsh or fish, your
shell will be asked to execute sh as a subshell in order to print
out the variables in a format which can be reliably parsed. sh must
be a POSIX-compliant shell in this case.

Note that shell variables which have not been exported as environment
variables (e.g. using the "export" keyword) may not be visible to
`exec-path-from-shell'.

Installation

Installable packages are available via MELPA: do
M-x package-install RET exec-path-from-shell RET.

Alternatively, download
the latest release or clone the repository, and install
exec-path-from-shell.el with M-x package-install-file.

Usage

Add the following to your init.el (after calling package-initialize):

(when (memq window-system '(mac ns x))
  (exec-path-from-shell-initialize))

This sets $MANPATH, $PATH and exec-path from your shell, but only on OS X
and Linux.

You can copy values of other environment variables by customizing
exec-path-from-shell-variables before invoking
exec-path-from-shell-initialize, or by calling
exec-path-from-shell-copy-env, e.g.:

(exec-path-from-shell-copy-env "PYTHONPATH")

This function may also be called interactively.

Setting up your shell startup files correctly

Note that your shell will inherit Emacs's environment variables when
it is run by exec-path-from-shell -- to avoid surprises your config
files should therefore set the environment variables to their exact
desired final values, i.e. don't do this:

export PATH=/usr/local/bin:$PATH

but instead do this:

export PATH=/usr/local/bin:/usr/bin:/bin

You should also set your environment variables so that they are
available to both interactive and non-interactive shells. In practical
terms, for most people this means setting them in ~/.profile,
~/.bash_profile, ~/.zshenv instead of ~/.bashrc and
~/.zshrc. By default, exec-path-from-shell checks for this
mistake, at the cost of some execution time. If your config files are
set up properly, you can set exec-path-from-shell-arguments
appropriately (often to nil) before calling
exec-path-from-shell-initialize to avoid this overhead.

Further help

  • C-h f exec-path-from-shell-initialize
  • C-h f exec-path-from-shell-copy-env

主要指标

概览
名称与所有者purcell/exec-path-from-shell
主编程语言Emacs Lisp
编程语言Emacs Lisp (语言数: 2)
平台
许可证Other
所有者活动
创建于2012-09-13 09:30:10
推送于2024-11-07 07:19:22
最后一次提交2024-11-07 07:19:15
发布数20
最新版本名称2.2 (发布于 )
第一版名称0.1 (发布于 )
用户参与
星数1.5k
关注者数34
派生数83
提交数128
已启用问题?
问题数94
打开的问题数4
拉请求数15
打开的拉请求数1
关闭的拉请求数13
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?