Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Initialize MANPATH #2

Merged
merged 4 commits into from

2 participants

@lunaryorn

Also copy $MANPATH from shell in exec-path-from-shell-initialize. Avoids mismatches between manpages shown with M-x man and the actual behaviour of the program.

This pull request also comprises some minor improvements, and adds a readme. The latter doesn't really belong here, but admittedly I was too lazy to open two pull requests :)

@purcell purcell merged commit f349bc2 into purcell:master
@purcell
Owner

Nice -- merged!

Thanks for that, particularly the README. Sooner or later I want to start using org-readme to generate these automatically, but I haven't got around to it yet.

I'll probably remove the hard-coded MANPATH and instead add a custom var which is a list of extra env vars to copy at initialization time -- the default value would be '("MANPATH").

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 6, 2012
  1. @lunaryorn

    Improve docstrings

    lunaryorn authored
  2. @lunaryorn

    Simplify initialization

    lunaryorn authored
  3. @lunaryorn
  4. @lunaryorn

    Add a readme

    lunaryorn authored
This page is out of date. Refresh to see the latest.
Showing with 81 additions and 5 deletions.
  1. +67 −0 README.md
  2. +14 −5 exec-path-from-shell.el
View
67 README.md
@@ -0,0 +1,67 @@
+exec-path-from-shell
+=====================
+
+A GNU Emacs library to setup environment variables from the user's shell.
+
+Motivation
+----------
+
+On OS X, an Emacs instance started from the graphical user interface will have a
+different environment than a shell in a terminal window, because OS X does not
+run a shell during the login. Obviously this will lead to unexpected results
+when calling external utilities like `make` from Emacs.
+
+This library intends to work around this problem by copying important
+environment variables from the user's shell.
+
+Installation
+------------
+
+ELPA packages are available on Marmalade and MELPA. Alternatively, [download][]
+the latest release or clone the repository, and install
+`exec-path-from-shell.el` with `M-x package-install-from-file`.
+
+Usage
+-----
+
+Add the following to your `init.el`:
+
+```scheme
+(when (memq window-system '(mac ns))
+ (exec-path-from-shell-initialize))
+```
+
+This sets `$MANPATH`, `$PATH` and `exec-path` from your shell, but only on OS X.
+
+You can copy values of other environment variables with
+`exec-path-from-shell-copy-env`, e.g.:
+
+```scheme
+(exec-path-from-shell-copy-env "PYTHONPATH")
+```
+
+This function may also be called interactively.
+
+Further help
+------------
+
+* `C-h f exec-path-from-shell-initialize`
+* `C-h f exec-path-from-shell-copy-env`
+
+License
+-------
+
+This program is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free Software
+Foundation; either version 2 of the License, or (at your option) any later
+version.
+
+This program is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along with
+this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
+Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+[download]: https://github.com/purcell/exec-path-from-shell/tags
View
19 exec-path-from-shell.el
@@ -57,6 +57,10 @@
;;; Code:
(defun exec-path-from-shell-getenv (name)
+ "Get the environment variable NAME from the user's shell.
+
+Execute $SHELL as interactive login shell, have it output the
+variable of NAME and return this output as string."
(with-temp-buffer
(call-process (getenv "SHELL") nil (current-buffer) nil
"--login" "-i" "-c" (concat "echo __RESULT=$" name))
@@ -65,17 +69,22 @@
;;;###autoload
(defun exec-path-from-shell-copy-env (name)
- "Set the environment variable with `NAME' to match the value seen in the user's shell."
+ "Set the environment variable $NAME from the user's shell.
+
+Return the value of the environment variable."
(interactive "sCopy value of which environment variable from shell? ")
(setenv name (exec-path-from-shell-getenv name)))
;;;###autoload
(defun exec-path-from-shell-initialize ()
- "Set the PATH environment variable and `exec-path' to match that seen in the user's shell."
+ "Initialize environment from the user's shell.
+
+Set $MANPATH, $PATH and `exec-path' from the corresponding
+variables in the user's shell."
(interactive)
- (let ((path-from-shell (exec-path-from-shell-getenv "PATH")))
- (setenv "PATH" path-from-shell)
- (setq exec-path (split-string path-from-shell path-separator))))
+ (exec-path-from-shell-copy-env "MANPATH")
+ (setq exec-path (split-string (exec-path-from-shell-copy-env "PATH")
+ path-separator)))
(provide 'exec-path-from-shell)
Something went wrong with that request. Please try again.