wbolster / emacs-direnv

direnv integration for emacs
BSD 3-Clause "New" or "Revised" License
347 stars 38 forks source link
autoenv awesome-sauce direnv elisp emacs env environment environment-variables envrc

============ emacs-direnv

.. image:: https://melpa.org/packages/direnv-badge.svg :alt: melpa badge

.. image:: https://stable.melpa.org/packages/direnv-badge.svg :alt: melpa stable badge

this package provides direnv_ integration for emacs.

.. _direnv: https://direnv.net/

it works by invoking direnv to obtain the environment for the current file, then updating the emacs variables process-environment and exec-path.

the result is that programs started from within emacs, such as inferior shells, linters, compilers, and test runners, will be looked up in the correct $PATH, and will be started with the correct environment variables set.

to get started, add this to your init.el:

.. code-block:: elisp

(use-package direnv :config (direnv-mode))

.. image:: https://cloud.githubusercontent.com/assets/748944/23811101/c82c40d0-05d4-11e7-8a79-74e1d80fa5cf.png :alt: mandatory screenshot

installation

direnv.el is available from melpa <https://melpa.org/#/direnv>_.

with use-package:

.. code-block:: elisp

(use-package direnv)

manually::

M-x package-install RET direnv RET

alternatively, put the elisp file somewhere in the loading path and load it explicitly:

.. code-block:: elisp

(require 'direnv)

also make sure that the direnv version (direnv version) is at least 2.8.0 since this package uses the json export capabilities (direnv export json).

usage

the command direnv-update-environment provides the core functionality of this package: it updates the emacs environment to the direnv environment for the current file. the minibuffer will show a message with a summary of the changes made to the environment, similar to what direnv does in a shell. its sibling command direnv-update-directory-environment does the same for buffers that don't have an associated file.

the global minor mode direnv-mode does the same, but automatically updates the emacs environment when the active buffer changes, so that the environment always matches the current file. to automatically enable this behaviour when emacs starts, put this in your ~/.emacs/init.el:

.. code-block:: elisp

(direnv-mode)

or use the use-package :config block:

.. code-block:: elisp

(use-package direnv :config (direnv-mode))

finally, the direnv-allow command acts like direnv allow from a shell: it allows loading the .envrc file associated with the current directory or one of its parent directories. this command is useful for new projects (always check whether the .envrc file is trustworthy), or after editing the .envrc file within emacs itself.

configuration

this packages offers various configuration settings. these settings can be set in a use-package :custom block, using (setq), or via the customize interface::

M-x customize-group RET direnv RET

the available settings are outlined below.

troubleshooting

if you experience problems, first check the buffer named *direnv*. this buffer contains the output of the last direnv invocation, which will likely contain more information about the source of the problem.

when an error happens, the direnv stderr will be automatically shown in the message area, but for non-fatal problems such as incorrect .envrc files you may have to open this buffer manually for inspection of the full output of the last direnv call.

to hide direnv errors such as .envrc is blocked, customize the variable warning-suppress-types.

contributing

praise? complaints? bugs? questions? ideas?

please use the github issue tracker.

credits

this emacs package was created by wouter bolsterlee (@wbolster) <https://github.com/wbolster>_.

it incorporates ideas from earlier packages created by jonathan lange (@jml) <https://github.com/jml> and christian romney (@christianromney) <https://github.com/christianromney>.

history

license

3-clause new bsd license; see LICENSE.rst.