Skip to content
This repository has been archived by the owner on Nov 17, 2018. It is now read-only.

Latest commit

 

History

History
139 lines (93 loc) · 1.9 KB

index.adoc

File metadata and controls

139 lines (93 loc) · 1.9 KB

Using direnv with ruby

Hi

Jonas Pfenniger Chevalier IRL

zimbatm everywhere else: twitter, github, …​

Works at Pusher doing pubsub messaging over websocket

Overview

25 minutes

  • presenting direnv

  • how to use with ruby

  • and 12factor apps

Context

  • shell

  • prompt

  • environment variables

Enter direnv

brew install direnv
echo 'eval "$(direnv hook bash)"' >> ~/.bashrc
exec bash

supports bash, zsh, fish, tcsh and more

packages for homebrew, debian, archlinux and nixos. or just grab the binary.

How it works

hook into shell

eval "direnv export <shell>" executed before every prompt

load .envrc in bash if found, export diff

Security model

~/.config/direnv/allowed/$(hash(path + .envrc content))

Basic usage

  • cd into directory, loads env

  • cd out, unloads env

The stdlib

injected into the bash .envrc context

  • PATH_add

  • load_prefix

  • dotenv

  • source_env / source_up

  • layout

  • use

  • …​

man direnv-stdlib

direnv stdlib | less

Extend the stdlib

Write your own in ~/.direnvrc

Build your own adventure^Wruby version switcher

ruby-install ruby 1.9.3

~/.direnvrc

use_ruby() {
  load_prefix "$HOME/.rubies/ruby-$1"
}

.envrc

use ruby 1.9.3-p551

Small improvements

~/.direnvrc

use_ruby() {
  load_prefix "$HOME/.rubies/$1"
  layout ruby
}

ruby-version() {
  use ruby ruby-"$(< .ruby-version)"
}

.envrc

ruby-version
dotenv

Git config

How to avoid having .direnv/ listed in git

$ git config core.excludesfile ~/.gitignore_global

Future

  • multiple profiles, direnv switch

  • dependency change-tracking

  • layout auto