• Stars
    star
    5,388
  • Rank 7,650 (Top 0.2 %)
  • Language
    Shell
  • License
    MIT License
  • Created almost 13 years ago
  • Updated about 1 year ago

Reviews

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

Repository Details

Directory-based environments.

Autoenv: Directory-based Environments Build Status

Magic per-project shell environments

What is it?

If a directory contains a .env file, it will automatically be executed when you cd into it. When enabled (set AUTOENV_ENABLE_LEAVE to a non-empty string), if a directory contains a .env.leave file, it will automatically be executed when you leave it.

This is great for...

  • auto-activating virtualenvs
  • auto-deactivating virtualenvs
  • project-specific environment variables
  • making millions

You can also nest envs within each other. How awesome is that!?

When executing, autoenv, will walk up the directories until the mount point and execute all .env files beginning at the top.

Usage

Follow the white rabbit:

$ echo "echo 'whoa'" > ./project/.env
$ cd ./project
whoa

Mind blown GIF

Installation (automated)

# with cURL
curl -#fLo- 'https://raw.githubusercontent.com/hyperupcall/autoenv/master/scripts/install.sh' | sh

# with wget
wget --show-progress -o /dev/null -O- 'https://raw.githubusercontent.com/hyperupcall/autoenv/master/scripts/install.sh' | sh

If you encounter some variant of a curl: command not found or wget: command not found error, please install either cURL or wget (with your package manager) and try again.

Installation (manual)

When installing manually, you first install autoenv with either Homebrew, npm, or Git. Then, you run a command to ensure autoenv is loaded when you open a terminal (this command depends on your default shell).

Installation Method

Note that depending on your shell and operating system, you may need to write to .zprofile instead of .zshrc, or write to .bash_profile instead of .bashrc (or visa-versa).

Using Homebrew

Prefer this if you're running macOS. Homebrew must be installed.

Click to expand content

First, download the autoenv homebrew formulae:

$ brew install 'autoenv'

Then, execute run of the following to ensure autoenv is loaded when you open a terminal:

# For Zsh shell (on Linux or macOS)
$ printf '%s\n' "source $(brew --prefix autoenv)/activate.sh" >> "${ZDOTDIR:-$HOME}/.zprofile"

# For Bash shell (on Linux)
$ printf '%s\n' "source $(brew --prefix autoenv)/activate.sh" >> ~/.bashrc

# For Bash shell (on macOS)
$ printf '%s\n' "source $(brew --prefix autoenv)/activate.sh" >> ~/.bash_profile

Using npm

Prefer this if you're running Linux or an unsupported version of macOS. npm must be installed (usually through NodeJS).

Click to expand content

First, download the @hyperupcall/autoenv npm package:

$ npm install -g '@hyperupcall/autoenv'

Then, execute run of the following to ensure autoenv is loaded when you open a terminal:

# For Zsh shell (on Linux or macOS)
$ printf '%s\n' "source $(npm root -g)/activate.sh" >> "${ZDOTDIR:-$HOME}/.zprofile"

# For Bash shell (on Linux)
$ printf '%s\n' "source $(npm root -g)/activate.sh" >> ~/.bashrc

# For Bash shell (on macOS)
$ printf '%s\n' "source $(npm root -g)/activate.sh" >> ~/.bash_profile

Using Git

Use this if you cannot install with Homebrew or npm.

Click to expand content

First, clone this repository:

$ git clone 'https://github.com/hyperupcall/autoenv' ~/.autoenv

Then, execute run of the following to ensure autoenv is loaded when you open a terminal:

# For Zsh shell (on Linux or macOS)
$ printf '%s\n' "source ~/.autoenv/activate.sh" >> "${ZDOTDIR:-$HOME}/.zprofile"

# For Bash shell (on Linux)
$ printf '%s\n' "source ~/.autoenv/activate.sh" >> ~/.bashrc

# For Bash shell (on macOS)
$ printf '%s\n' "source ~/.autoenv/activate.sh" >> ~/.bash_profile

Configuration

Before sourceing activate.sh, you can set the following variables:

  • AUTOENV_AUTH_FILE: Authorized env files; defaults to ~/.autoenv_authorized if it exists, otherwise, ~/.local/state/autoenv/authorized_list
  • AUTOENV_NOTAUTH_FILE: Env files not authorized to be sourced; defaults to a file in the same directory as ~/.autoenv_authorized (master branch only)
  • AUTOENV_ENV_FILENAME: Name of the .env file; defaults to .env
  • AUTOENV_LOWER_FIRST: Set this variable to a non-empty string to flip the order of .env files executed
  • AUTOENV_ENV_LEAVE_FILENAME: Name of the .env.leave file; defaults to .env.leave
  • AUTOENV_ENABLE_LEAVE: Set this to a non-empty string in order to enable source env when leaving
  • AUTOENV_ASSUME_YES: Set this variable to a non-empty string to silently authorize the initialization of new environments
  • AUTOENV_VIEWER: Program used to display env files prior to authorization; defaults to cat (master branch only)
  • AUTOENV_PRESERVE_CD: Set this variable to a non-empty string to prevent the cd builtin from being overridden (to active autoenv, you must invoke autoenv_init within a cd function of your own) (master branch only)

Shells

autoenv is tested on:

  • Bash
  • Zsh
  • Dash
  • Fish is supported by autoenv_fish
  • More to come

Disclaimer

Autoenv overrides cd (unless AUTOENV_PRESERVE_CD is set to a non-empty string). If you already do this, invoke autoenv_init within your custom cd after sourcing activate.sh.

Autoenv can be disabled via unset -f cd if you experience I/O issues with certain file systems, particularly those that are FUSE-based (such as smbnetfs).

Other info

To uninstall autoenv, see ./docs/uninstall.md.

To update autoenv, see ./docs/updating.md.

Attributions

Autoenv was originally created by @kennethreitz. Later, ownership was transfered to @inishchith. As of August 22nd, 2021, Edwin Kofler (@hyperupcall) owns and maintains the project.

More Repositories

1

basalt

The rock-solid Bash package manager
Shell
44
star
2

bake

A Bash-based Make alternative.
Shell
25
star
3

bash-object

The _first_ Bash library for manipulating heterogenous data hierarchies
Shell
22
star
4

woof

The version manager to end all version managers
Shell
21
star
5

dotfox

User and system-wide dotfile manager
Nim
10
star
6

bash-toml

A kickass Toml parser written in pure Bash
Shell
10
star
7

bash-args

A cute little Bash library for blazing fast argument parsing
Shell
9
star
8

awesome-basalt

A collection of Basalt (Bash) packages
Shell
7
star
9

bash-algo

Common algorithms implemented in pure Bash
Shell
7
star
10

bash-json

Parse JSON in Bash
Shell
7
star
11

bash-term

Bash library for terminal escape sequences
Shell
7
star
12

fox-night

Fox Night
TypeScript
6
star
13

cactus

A hotkey launcher
Go
6
star
14

typescript-runtime-transpiler

πŸ¦•Transpile Node APIs to Deno 😎
TypeScript
6
star
15

hookah

An elegantly minimal solution for Git hooks
Shell
5
star
16

dotfiles

My dotfiles! ^_^
Shell
5
star
17

config

A deno module that helps you load configuration
TypeScript
4
star
18

fox-suite

🦊 A sly suite of tools for web development 😏
TypeScript
4
star
19

vscode-assorted-languages

Never worry about syntax highlighting for miscellaneous files again!
JSON
4
star
20

awesome-icons

A collection of Awesome resources related to icon and icon design!
4
star
21

glue

Hypergeneral boilerplate manager and task runner
Shell
4
star
22

bash_config

fish_config, but for Bash
Shell
3
star
23

hacklang-sucrase

Hacklang uwu
TypeScript
3
star
24

ensure

Ensure you are running a minimum version of Deno, Typescript, or V8
TypeScript
3
star
25

redpanda

Cross-repository refactoring
Shell
3
star
26

dockerized-mars

Configuration for spinning up MIPS Assembly and Runtime Simulator (MARS) in a Docker container
Dockerfile
2
star
27

periodic-table-v2

Modern website that elegantly shows an interactive periodic table.
Vue
2
star
28

infrastructure-old

my iac
Shell
2
star
29

hackclub-community

Showcases the Hack Club Community!
Go
2
star
30

blog

My blog
HTML
2
star
31

baeuda

Create, edit, and study flashcards offline using Baeuda.
CSS
2
star
32

dockerized-mmlogic

Configuration for spinning up MultiMedia Logic in a Docker container
Dockerfile
2
star
33

bash-core

Core functions for any Bash program
Shell
2
star
34

dotmgr

A dotfile deployment framework
Rust
2
star
35

sort-package-json

sort package json file
TypeScript
1
star
36

repos

Simple repository that categorizes most of my repositories
Shell
1
star
37

dotshellgen

Dotfile concatenation by categorization
Shell
1
star
38

dotshellextract

Extract your dotfiles for reusability
Shell
1
star
39

minecraft-bot

Minecraft bot for the HackClub slack - #minecraft-bridge
JavaScript
1
star
40

bash-error

Ergonomic error handling in Bash
Shell
1
star
41

cmdcap

Automated command capturer
Shell
1
star
42

deno-fox

Fox is a little utility that helps you bootstrap Deno applications
TypeScript
1
star
43

urocyon-cookbook

My cookbook for the urocyon scaffolding system
JavaScript
1
star
44

sigag

Study efficiently with a simple pomodoro timer using sigag.
CSS
1
star
45

bats-all

Aggregation of the three most popular Bats utility libraries
Shell
1
star
46

developer-surveys

1
star
47

hyperupcall

My readme!
JavaScript
1
star
48

bash-utility

A standard utility library for Bash
Shell
1
star
49

volant

TheDevFam's volant language for the Replit Programming Language Jam
Go
1
star
50

shelltest

A test runner for POSIX-compliant shells
Shell
1
star
51

repomgr

My task automator
TypeScript
1
star
52

xdgbasedirectoryspecification.com

Use the XDG Base Directory Specification!
HTML
1
star
53

bash-str

String manipulation functions for Bash
Shell
1
star