• Stars
    star
    2
  • Language
    Haskell
  • License
    MIT License
  • Created almost 8 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Safe helpers for accessing and modifying environment variables

env-extra

https://github.com/d12frosted/env-extra/workflows/CI/badge.svg https://img.shields.io/hackage/v/env-extra.svg

Safe helpers for accessing and modifying environment variables.

In order to use functions from this package, just import System.Environment.Extra module.

Setting environment variables

>>> :t setEnv
(MonadThrow m, MonadIO m) => Text -> Text -> m ()
>>> setEnv "NAME" "Boris"
>>> setEnv "AGE" "12"

Reading environment variables

When it comes to reading environment variables there are three functions you should choose from:

  • getEnv - the lifted and unsafe version of System.Environment.lookupEnv that works in any MonadThrow and MonadIO monad and allows one to get any IsString value. When variable not found, an exception is thrown.
    >>> getEnv "NAME"
    *** Exception: Could not find value of $NAME in environment.
    >>> getEnv "HOME"
    "/Users/d12frosted"
        
  • envMaybe - the lifted version of System.Environment.lookupEnv that returns any IsString value.
    >>> getEnv "NAME"
    Nothing
    >>> getEnv "HOME"
    Just "/Users/d12frosted"
        
  • envRead - the lifted version of System.Environment.lookupEnv that allows one to provide a parser (reader) for that value.
    >>> setEnv "AGE" "10"
    >>> envMaybe "AGE"
    Just "10"
    >>> envRead decimal "AGE"
    Just 10
    >>> envRead hexadecimal "AGE"
    Just 16
    >>> envRead hexadecimal "HOME"
    Nothing
        

Both getEnv and envMaybe return an IsString value, which can come handy in many scenarios. In the following example getEnv accepts Text value, while putStrLn accepts String value and getEnv chains in both cases.

>>> setEnv "WHAAT" "HOME"
>>> getEnv "WHAAT"
"HOME"
>>> getEnv "WHAAT" >>= putStrLn
HOME
>>> getEnv "WHAAT" >>= getEnv
"/Users/d12frosted"

Using with stack

Just add env-extra to stack.yaml file.

extra-deps:
- git: https://github.com/d12frosted/env-extra
  commit: 78eba1d8299be64721a96178425bf6c66776f573

More Repositories

1

homebrew-emacs-plus

Emacs Plus formulae for the Homebrew package manager
Ruby
2,143
star
2

vulpea

A collection of functions for note taking based on `org` and `org-roam`.
Emacs Lisp
222
star
3

flyspell-correct

Distraction-free words correction with flyspell via selected interface.
Emacs Lisp
196
star
4

environment

dotfiles
Emacs Lisp
121
star
5

elpa-mirror

Mirror for some Emacs package archives
Emacs Lisp
96
star
6

dotbot-brew

Install brew packages using dotbot
Python
42
star
7

vino

It's your cellar, your dear cantina.
Emacs Lisp
36
star
8

counsel-osx-app

Launch OSX applications via ivy interface
Emacs Lisp
24
star
9

UnityLibrarySwitcher

Unity plugin for switching build targets, git branches without endless assets reimport. Not maintained anymore.
C#
19
star
10

git-config-manager

Manage git repository configurations with ease
Haskell
8
star
11

mirror-elpa

(To) mirror Emacs Lisp Package Archive(s)
Shell
8
star
12

d12frosted.io

Personal site
Haskell
8
star
13

orgability

Reading list manager for Emacs with offline access support.
Emacs Lisp
7
star
14

publicatorg

Make your vulpea notes public
Emacs Lisp
5
star
15

fancy-yank

apply transformation upon yanking
Emacs Lisp
4
star
16

emacs-addiction-mode

M-x doctor instead of C-x C-c
Emacs Lisp
4
star
17

barberry.io

Emacs Lisp
4
star
18

emacs-ukrainian-input-method

Ukrainian macOS-like input method
Emacs Lisp
4
star
19

org-drawer-list

Tame your lists in a drawer
Emacs Lisp
3
star
20

emacs-plus-basis

Emacs Lisp
3
star
21

CanonicalPath

Abstract data type for canonical paths with some pretty operations. Not maintained anymore.
Haskell
3
star
22

talks

TeX
2
star
23

d12frosted

1
star
24

path-extra

Path helpers for my personal projects
Haskell
1
star
25

bomberman-player

Haskell
1
star
26

fish-mode

Major mode for editing fish shell scripts
Emacs Lisp
1
star