1
0
mirror of https://github.com/Tarrasch/zsh-autoenv.git synced 2024-11-25 16:31:00 +02:00
Go to file
2015-05-06 21:33:40 +02:00
lib varstash: fix get_autostash_array_name for Zsh 4.3.17 (Travis) 2015-04-23 17:57:46 +02:00
tests Change default for AUTOENV_FILE_LEAVE to .env_leave 2015-05-06 20:28:23 +02:00
.gitignore gitignore tests/*.err 2014-12-02 22:49:01 +01:00
.travis.yml travis: fix tests 2015-04-23 21:52:25 +02:00
autoenv.plugin.zsh travis: fix tests 2015-04-23 21:52:25 +02:00
autoenv.zsh Merge pull request #27 from blueyed/add-doc 2015-05-06 21:24:28 +02:00
init.zsh Create init.zsh to make compatible with prezto 2015-01-19 15:25:42 +01:00
Makefile make test_full: use zsh 4 (/opt/zsh4/bin/zsh) and zsh 5 2015-04-23 19:54:44 +02:00
README.md Update README.md 2015-05-06 21:33:40 +02:00

Bitdeli Badge

Build Status

Autoenv for Zsh

zsh-autoenv automatically sources .env files, typically used in project root directories.

It handles "enter" and leave" events, nesting, and stashing of variables (overwriting and restoring).

Features

  • Support for enter and leave events, which can use the same file. By default .env is used for entering, and .env_leave for leaving.
  • Asks for confirmation / authentication before sourcing a .env file, and remembers whitelisted files by its hash.
  • Test suite.
  • Written in Zsh.

Variable stashing

You can use autostash in your .env files to overwrite some variable, e.g. $PATH. When leaving the directory, it will be automatically restored.

% echo 'echo ENTERED; autostash FOO=changed' > project/.env
% FOO=orig
% cd project
Attempting to load unauthorized env file!
-rw-rw-r-- 1 user user 36 Mai  6 20:38 /tmp/project/.env

**********************************************

echo ENTERED; autostash FOO=changed

**********************************************

Would you like to authorize it? (type 'yes') yes
ENTERED
project % echo $FOO
changed
% cd ..
% echo $FOO
orig

There is also stash, unstash and autounstash, in case you want to have more control.

The varstash library has been taken from smartcd, and was optimized for Zsh.

Writing your .env file

autoenv_source_parent()

zsh-autoenv will stop looking for .env files after the first one has been found. But you can use the function autoenv_source_parent to source a parent .env file from there.

Installation

Clone the repository and source it from your ~/.zshrc file:

% git clone https://github.com/Tarrasch/zsh-autoenv ~/.dotfiles/lib/zsh-autoenv
% echo 'source ~/.dotfiles/lib/zsh-autoenv/autoenv.zsh' >> ~/.zshrc

Using antigen

antigen-bundle Tarrasch/zsh-autoenv

Using zgen

Add the following to your .zshrc where you are loading your plugins:

zgen load Tarrasch/zsh-autoenv

Configuration

You can use the following variables to control zsh-autoenv's behavior. Add them to your ~/.zshrc file, before sourcing/loading zsh-autoenv.

AUTOENV_FILE_ENTER

Name of the file to look for when entering directories.

Default: .env

AUTOENV_FILE_LEAVE

Name of the file to look for when leaving directories. Requires AUTOENV_HANDLE_LEAVE=1.

Default: .env_leave

AUTOENV_LOOK_UPWARDS

Look for .env files in parent dirs?

Default: 1

AUTOENV_HANDLE_LEAVE

Handle leave events when changing away from a subtree, where an "enter" event was handled?

Default: 1

AUTOENV_DISABLED

(Temporarily) disable zsh-autoenv. This gets looked at in the chpwd handler.

Default: 0

AUTOENV_DEBUG

Enable debugging. Multiple levels are supported (max 2).

Default: 0

History

This started as a optimized version of the bash plugin autoenv but for Zsh, but grew a lot of functionality on top of it (inspired by smartcd).

The code was initially based on @joshuaclayton's dotfiles. In September 2013 @Tarrasch packaged into a nice antigen-compatible unit with integration tests. Since November 2014, @blueyed took over and added many many nice features, mainly inspired from smartcd