Giter Club home page Giter Club logo

setenv-file's Introduction

setenv-file

Set or unset environment variables from an "env" or dotenv file.

This package provides two interactive functions:

  1. setenv-file: Set all the environment variables defined in an env file.
  2. setenv-file-unset: Unset all the environment variables defined in an env file.

When used interactively, each function prompts for a file. By default, the prompt begins at setenv-file-dir.

Installation

Copy setenv-file.el to your machine, and load it:

(load "/path/to/setenv-file.el")

Or, using straight:

(straight-use-package
 '(setenv-file :type git
	       :host github
	       :repo "cfclrk/setenv-file"))

Usage

Start by creating an env file in setenv-file-dir (by default, ~/.env/). For example, create this file in ~/.env/foo:

FOO=~/foo
BAR=$FOO/bar
ОФИС=ДОМ
BAZ=nosubst:FOO$BAR

Now, you can run:

  • M-x setenv-file, which will prompt you for a file. All the environment variables defined in the file will be set.
  • M-x setenv-file-unset, which will prompt you for a file. All the environment variables defined in the file will be unset.

Usage from Elisp

To set env variables defined in ~/.env/foo:

(setenv-file (expand-file-name "~/.env/foo"))

Or, if you have a string instead of a file:

(setenv-file-str "FOO=foo\nBAR=bar")

Usage from org-mode

The example below shows a convenient way to declare and set environment variables in an org document:

#+NAME: env
| Var  | Value           |
|------+-----------------|
| FOO  | ~/foo           |
| BAR  | $FOO/bar        |
| ОФИС | ДОМ             |
| BAZ  | nosubst:FOO$BAR |

#+begin_src emacs-lisp :var env=env
  (setenv-file-set-pairs env)
#+end_src

File Format

Each line in the file should be in a KEY=VALUE format, with one entry per line. This package does not invoke a shell to interpret the file, so most shell-isms will not work. However, the env file may:

  • Use existing environment variables
  • Define an environment variable and use it in successive lines
  • A ~ is expanded if it is the first character in the value
  • If a value starts with `nosubst:`, no variable substitution will be performed. You need this if there is a literal $ in the value.

Development

  1. make dep: Install dependencies
  2. make test: Run unit tests (you must run make dep first!)
  3. make doc: Runs an org export on doc/doc.org which creates:
    • README.md
    • The ;;; Commentary section in setenv-file.el
    • Package texinfo (.texi and .info) in doc/

See Also

setenv-file's People

Contributors

cfclrk avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.