1 [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/Tarrasch/zsh-autoenv/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
3 [![Build Status](https://travis-ci.org/Tarrasch/zsh-autoenv.svg?branch=master)](https://travis-ci.org/Tarrasch/zsh-autoenv)
7 zsh-autoenv automatically sources `.env` files, typically used in project
10 It handles "enter" and leave" events, nesting, and stashing of
11 variables (overwriting and restoring).
15 - Support for enter and leave events, which can use the same file.
16 By default `.env` is used for entering, and `.env_leave` for leaving.
17 - Asks for confirmation / authentication before sourcing a `.env` file, and
18 remembers whitelisted files by its hash.
24 You can use `autostash` in your `.env` files to overwrite some variable, e.g.
25 `$PATH`. When leaving the directory, it will be automatically restored.
27 % echo 'echo ENTERED; autostash FOO=changed' > project/.env
30 Attempting to load unauthorized env file!
31 -rw-rw-r-- 1 user user 36 Mai 6 20:38 /tmp/project/.env
33 **********************************************
35 echo ENTERED; autostash FOO=changed
37 **********************************************
39 Would you like to authorize it? (type 'yes') yes
47 There is also `stash`, `unstash` and `autounstash`, in case you want to
50 The varstash library has been taken from smartcd, and was optimized for Zsh.
53 ## Writing your .env file
55 ### `autoenv_source_parent()`
57 zsh-autoenv will stop looking for `.env` files after the first one has been
58 found. But you can use the function `autoenv_source_parent` to source a
59 parent `.env` file from there.
64 Clone the repository and source it from your `~/.zshrc` file:
66 % git clone https://github.com/Tarrasch/zsh-autoenv ~/.dotfiles/lib/zsh-autoenv
67 % echo 'source ~/.dotfiles/lib/zsh-autoenv/autoenv.zsh' >> ~/.zshrc
69 ### Using [antigen](https://github.com/zsh-users/antigen)
71 antigen-bundle Tarrasch/zsh-autoenv
73 ### Using [zgen](https://github.com/tarjoilija/zgen)
75 Add the following to your `.zshrc` where you are loading your plugins:
77 zgen load Tarrasch/zsh-autoenv
82 You can use the following variables to control zsh-autoenv's behavior.
83 Add them to your `~/.zshrc` file, before sourcing/loading zsh-autoenv.
85 ### AUTOENV\_FILE\_ENTER
86 Name of the file to look for when entering directories.
90 ### AUTOENV\_FILE\_LEAVE
91 Name of the file to look for when leaving directories.
92 Requires `AUTOENV_HANDLE_LEAVE=1`.
96 ### AUTOENV\_LOOK\_UPWARDS
97 Look for .env files in parent dirs?
101 ### AUTOENV\_HANDLE\_LEAVE
102 Handle leave events when changing away from a subtree, where an "enter"
107 ### AUTOENV\_DISABLED
108 (Temporarily) disable zsh-autoenv. This gets looked at in the chpwd handler.
113 Enable debugging. Multiple levels are supported (max 2).
119 - https://github.com/cxreg/smartcd
120 - https://github.com/kennethreitz/autoenv
125 This started as a optimized version of
126 [autoenv](https://github.com/kennethreitz/autoenv) for Zsh, but grew a lot of
127 functionality on top of it (inspired by
128 [smartcd](https://github.com/cxreg/smartcd)).
130 The code was initially based on [Joshua Clayton](https://github.com/joshuaclayton)'s work.