Code Monkey home page Code Monkey logo

dotenv.el's Introduction

dotenv.el — Plugin for loading .env project files.

Dotenv parser by following rules:

  • skip empty lines
  • trim every string (all spaces before first non-whitespace char and after last non-whitespace char will be removed)
  • skip commentary lines (# at the line start)
  • skip lines which doesn’t look like an proper assignment
  • variable name and its value will be trimmed

Installation

use-package

(use-package dotenv
  :ensure nil
  :quelpa
  (dotenv :repo "pkulev/dotenv.el"
          :fetcher github :upgrade t))

Examples

Integration with projectile

Hook for loading project’s .env (if exists) after switching project via projectile.

(use-package dotenv
  :ensure nil
  :after projectile
  :quelpa
  (dotenv :repo "pkulev/dotenv.el"
          :fetcher github :upgrade t)
  :config
  (defun dotenv-projectile-hook ()
   "Projectile hook."
   (dotenv-update-project-env (projectile-project-root)))

  (add-to-list 'projectile-after-switch-project-hook #'dotenv-projectile-hook))

Transform variable name or contents using dotenv-transform-alist

In this example .env file contains PYTHONPATH among other vaiables. Assuming that PYTHONPATH contains list of pathes (delimeted by ’:’) relative to the project’s root we can transform it into absolute. To do that add to dotenv-transform-alist a pair of a predicate function and a transform function. Predicate function takes k and v and returns t or nil, transform function takes k and v and returns two-element list with new values for k and v.

(use-package dotenv
  :ensure nil
  :after projectile
  :quelpa
  (dotenv :repo "pkulev/dotenv.el"
          :fetcher github :upgrade t)
  :config
  (defun dotenv-absolutify-pythonpath (k v)
    (list k (dotenv-absolutify-path-var-in-project v)))

  (add-to-list
   'dotenv-transform-alist
   '((lambda (k v) (string= k "PYTHONPATH")) . dotenv-absolutify-pythonpath))

  (defun dotenv-projectile-hook ()
   "Projectile hook."
   (dotenv-update-project-env (projectile-project-root)))

  (add-to-list 'projectile-after-switch-project-hook #'dotenv-projectile-hook))

dotenv.el's People

Contributors

elken avatar pkulev avatar

Watchers

 avatar  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.