README: Move explanation of direnv_layout_dir into example implementation

It reads much more clearly in this manner,
as the documentation is presented alongside the thing it is documenting
This commit is contained in:
Bryan Bennett 2022-04-07 09:57:44 -04:00
parent e1df1d7484
commit 1741888b4c
No known key found for this signature in database
GPG key ID: EF90E3E98B8F5C0B

View file

@ -219,7 +219,13 @@ The following example will create a unique directory name per project
in `$HOME/.cache/direnv/layouts/`:
```bash
# $HOME/.config/direnv/direnvrc
# Place in "$HOME"/.config/direnv/direnvrc
# Two things to know:
# * `direnv_layour_dir` is called once for every {.direnvrc,.envrc} sourced
# * The indicator for a different direnv file being sourced is a different `$PWD` value
# This means we can hash `$PWD` to get a fully unique cache path for any given environment
: ${XDG_CACHE_HOME:=$HOME/.cache}
declare -A direnv_layout_dirs
direnv_layout_dir() {
@ -229,8 +235,6 @@ direnv_layout_dir() {
)}"
}
```
During direnv setup `direnv_layout_dir` can be called multiple times and with different values of `$PWD`
(when other `.envrc` files are included). Therefore cache its results in dictionary `direnv_layout_dirs`.
## Watching additional files