2013-09-16 12:27:08 +03:00
|
|
|
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/Tarrasch/zsh-autoenv/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
|
|
|
|
|
2014-12-04 08:58:45 +02:00
|
|
|
[![Build Status](https://travis-ci.org/Tarrasch/zsh-autoenv.svg?branch=master)](https://travis-ci.org/Tarrasch/zsh-autoenv)
|
2013-09-08 19:50:20 +03:00
|
|
|
|
2015-05-06 21:42:42 +03:00
|
|
|
# Autoenv for Zsh
|
2013-09-08 18:14:28 +03:00
|
|
|
|
2015-05-22 00:58:26 +03:00
|
|
|
zsh-autoenv automatically sources (known/whitelisted) `.autoenv.zsh` files,
|
|
|
|
typically used in project root directories.
|
2013-09-08 18:14:28 +03:00
|
|
|
|
2015-05-06 21:42:42 +03:00
|
|
|
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.
|
2015-05-22 00:58:26 +03:00
|
|
|
By default `.autoenv.zsh` is used for entering, and `.autoenv_leave.zsh`
|
|
|
|
for leaving.
|
2015-05-14 02:36:33 +03:00
|
|
|
- Interactively asks for confirmation / authentication before sourcing an
|
2015-05-22 00:58:26 +03:00
|
|
|
unknown `.autoenv.zsh` file, and remembers whitelisted files by their
|
|
|
|
hashed content.
|
2015-05-06 21:42:42 +03:00
|
|
|
- Test suite.
|
|
|
|
- Written in Zsh.
|
|
|
|
|
|
|
|
### Variable stashing
|
|
|
|
|
2015-05-22 00:58:26 +03:00
|
|
|
You can use `autostash` in your `.autoenv.zsh` files to overwrite some
|
|
|
|
variable, e.g. `$PATH`. When leaving the directory, it will be automatically
|
|
|
|
restored.
|
2015-05-06 21:42:42 +03:00
|
|
|
|
2015-05-22 00:58:26 +03:00
|
|
|
% echo 'echo ENTERED; autostash FOO=changed' > project/.autoenv.zsh
|
2015-05-06 21:42:42 +03:00
|
|
|
% FOO=orig
|
|
|
|
% cd project
|
|
|
|
Attempting to load unauthorized env file!
|
2015-05-22 00:58:26 +03:00
|
|
|
-rw-rw-r-- 1 user user 36 Mai 6 20:38 /tmp/project/.autoenv.zsh
|
2015-05-06 21:42:42 +03:00
|
|
|
|
|
|
|
**********************************************
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
2015-05-22 00:58:26 +03:00
|
|
|
## Writing your .autoenv.zsh file
|
2015-05-06 21:42:42 +03:00
|
|
|
|
|
|
|
### `autoenv_source_parent()`
|
|
|
|
|
2015-05-22 00:58:26 +03:00
|
|
|
zsh-autoenv will stop looking for `.autoenv.zsh` files after the first one has
|
|
|
|
been found. But you can use the function `autoenv_source_parent` to source a
|
|
|
|
parent `.autoenv.zsh` file from there.
|
2013-09-08 18:14:28 +03:00
|
|
|
|
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
2015-05-06 21:42:42 +03:00
|
|
|
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
|
|
|
|
|
2014-12-11 17:31:41 +02:00
|
|
|
### Using [antigen](https://github.com/zsh-users/antigen)
|
2013-09-08 18:14:28 +03:00
|
|
|
|
|
|
|
antigen-bundle Tarrasch/zsh-autoenv
|
|
|
|
|
2015-02-18 17:30:43 +02:00
|
|
|
### Using [zgen](https://github.com/tarjoilija/zgen)
|
|
|
|
|
|
|
|
Add the following to your `.zshrc` where you are loading your plugins:
|
|
|
|
|
|
|
|
zgen load Tarrasch/zsh-autoenv
|
|
|
|
|
2014-12-11 17:31:41 +02:00
|
|
|
|
2015-05-06 21:42:42 +03:00
|
|
|
## 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.
|
|
|
|
|
2015-05-22 00:58:26 +03:00
|
|
|
Default: `.autoenv.zsh`
|
2015-05-06 21:42:42 +03:00
|
|
|
|
|
|
|
### AUTOENV\_FILE\_LEAVE
|
|
|
|
Name of the file to look for when leaving directories.
|
|
|
|
Requires `AUTOENV_HANDLE_LEAVE=1`.
|
|
|
|
|
2015-05-22 00:58:26 +03:00
|
|
|
Default: `.autoenv_leave.zsh`
|
2015-05-06 21:42:42 +03:00
|
|
|
|
|
|
|
### AUTOENV\_LOOK\_UPWARDS
|
2015-05-22 00:58:26 +03:00
|
|
|
Look for zsh-autoenv "enter" files in parent dirs?
|
2015-05-06 21:42:42 +03:00
|
|
|
|
|
|
|
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`
|
|
|
|
|
|
|
|
|
|
|
|
## Related projects
|
|
|
|
- https://github.com/cxreg/smartcd
|
|
|
|
- https://github.com/kennethreitz/autoenv
|
|
|
|
|
2014-12-11 17:31:41 +02:00
|
|
|
|
2015-05-06 21:42:42 +03:00
|
|
|
## History
|
2014-12-11 17:31:41 +02:00
|
|
|
|
2015-05-06 22:33:40 +03:00
|
|
|
This started as an optimized version of the bash plugin
|
|
|
|
[autoenv](https://github.com/kennethreitz/autoenv) but for Zsh, and grew a lot
|
|
|
|
of functionality on top of it (inspired by [smartcd]).
|
|
|
|
|
|
|
|
The code was initially based on
|
|
|
|
[@joshuaclayton](https://github.com/joshuaclayton)'s dotfiles.
|
|
|
|
In September 2013 [@Tarrasch](https://github.com/Tarrasch) packaged it into a
|
|
|
|
nice [antigen]-compatible unit with integration tests. Since November 2014,
|
|
|
|
[@blueyed](https://github.com/blueyed) took over and added many many nice
|
|
|
|
features, mainly inspired by [smartcd].
|
|
|
|
|
|
|
|
[antigen]: https://github.com/Tarrasch/antigen-hs
|
|
|
|
[smartcd]: https://github.com/cxreg/smartcd
|