]> Sergey Matveev's repositories - zsh-autoenv.git/blob - README.md
Remove globals: _autoenv_source_dir, _autoenv_chpwd_prev_dir
[zsh-autoenv.git] / README.md
1 [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/Tarrasch/zsh-autoenv/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
2
3 [![Build Status](https://travis-ci.org/Tarrasch/zsh-autoenv.svg?branch=master)](https://travis-ci.org/Tarrasch/zsh-autoenv)
4
5 # Autoenv for Zsh
6
7 zsh-autoenv automatically sources (known/whitelisted) `.autoenv.zsh` files,
8 typically used in project root directories.
9
10 It handles "enter" and leave" events, nesting, and stashing of
11 variables (overwriting and restoring).
12
13 ## Features
14
15  - Support for enter and leave events, which can use the same file.
16    By default `.autoenv.zsh` is used for entering, and `.autoenv_leave.zsh`
17    for leaving.
18  - Interactively asks for confirmation / authentication before sourcing an
19    unknown `.autoenv.zsh` file, and remembers whitelisted files by their
20    hashed content.
21  - Test suite.
22  - Written in Zsh.
23
24 ### Variable stashing
25
26 You can use `autostash` in your `.autoenv.zsh` files to overwrite some
27 variable, e.g.  `$PATH`.  When leaving the directory, it will be automatically
28 restored.
29
30     % echo 'echo ENTERED; autostash FOO=changed' > project/.autoenv.zsh
31     % FOO=orig
32     % cd project
33     Attempting to load unauthorized env file!
34     -rw-rw-r-- 1 user user 36 Mai  6 20:38 /tmp/project/.autoenv.zsh
35
36     **********************************************
37
38     echo ENTERED; autostash FOO=changed
39
40     **********************************************
41
42     Would you like to authorize it? (type 'yes') yes
43     ENTERED
44     project % echo $FOO
45     changed
46     % cd ..
47     % echo $FOO
48     orig
49
50 There is also `stash`, `unstash` and `autounstash`, in case you want to
51 have more control.
52
53 The varstash library has been taken from smartcd, and was optimized for Zsh.
54
55
56 ## Writing your .autoenv.zsh file
57
58 ### `autoenv_source_parent()`
59
60 zsh-autoenv will stop looking for `.autoenv.zsh` files after the first one has
61 been found.  But you can use the function `autoenv_source_parent` to source a
62 parent `.autoenv.zsh` file from there.
63
64
65 ## Installation
66
67 Clone the repository and source it from your `~/.zshrc` file:
68
69     % git clone https://github.com/Tarrasch/zsh-autoenv ~/.dotfiles/lib/zsh-autoenv
70     % echo 'source ~/.dotfiles/lib/zsh-autoenv/autoenv.zsh' >> ~/.zshrc
71
72 ### Using [antigen](https://github.com/zsh-users/antigen)
73
74     antigen-bundle Tarrasch/zsh-autoenv
75
76 ### Using [zgen](https://github.com/tarjoilija/zgen)
77
78 Add the following to your `.zshrc` where you are loading your plugins:
79
80     zgen load Tarrasch/zsh-autoenv
81
82
83 ## Configuration
84
85 You can use the following variables to control zsh-autoenv's behavior.
86 Add them to your `~/.zshrc` file, before sourcing/loading zsh-autoenv.
87
88 ### AUTOENV\_FILE\_ENTER
89 Name of the file to look for when entering directories.
90
91 Default: `.autoenv.zsh`
92
93 ### AUTOENV\_FILE\_LEAVE
94 Name of the file to look for when leaving directories.
95 Requires `AUTOENV_HANDLE_LEAVE=1`.
96
97 Default: `.autoenv_leave.zsh`
98
99 ### AUTOENV\_LOOK\_UPWARDS
100 Look for zsh-autoenv "enter" files in parent dirs?
101
102 Default: `1`
103
104 ### AUTOENV\_HANDLE\_LEAVE
105 Handle leave events when changing away from a subtree, where an "enter"
106 event was handled?
107
108 Default: `1`
109
110 ### AUTOENV\_DISABLED
111 (Temporarily) disable zsh-autoenv. This gets looked at in the chpwd handler.
112
113 Default: 0
114
115 ### `AUTOENV_DEBUG`
116 Enable debugging. Multiple levels are supported (max 2).
117
118 Default: `0`
119
120
121 ## Related projects
122 - https://github.com/cxreg/smartcd
123 - https://github.com/kennethreitz/autoenv
124
125
126 ## History
127
128 This started as an optimized version of the bash plugin
129 [autoenv](https://github.com/kennethreitz/autoenv) but for Zsh, and grew a lot
130 of functionality on top of it (inspired by [smartcd]).
131
132 The code was initially based on
133 [@joshuaclayton](https://github.com/joshuaclayton)'s dotfiles.
134 In September 2013 [@Tarrasch](https://github.com/Tarrasch) packaged it into a
135 nice [antigen]-compatible unit with integration tests. Since November 2014,
136 [@blueyed](https://github.com/blueyed) took over and added many many nice
137 features, mainly inspired by [smartcd].
138
139 [antigen]: https://github.com/Tarrasch/antigen-hs
140 [smartcd]: https://github.com/cxreg/smartcd