Linux/direnv: Difference between revisions
< Linux
Created page with "Loads variables from .envrc on cd into a directory and unloads them on cd out https://pydevtools.com/handbook/reference/direnv/ sudo apt install direnv # bash (~/.bashrc) eval "$(direnv hook bash)"" |
No edit summary |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 7: | Line 7: | ||
# bash (~/.bashrc) | # bash (~/.bashrc) | ||
eval "$(direnv hook bash)" | eval "$(direnv hook bash)" | ||
Allow config file: | |||
direnv allow . | |||
default env file:: | |||
.envrc | |||
full bash script style | |||
Only if enabled in config: | |||
.env | |||
static key=var pairs | |||
Example sourcing a python environment: | |||
.envrc | |||
source .venv/bin/activate | |||
Built in python helper example (The built-in layout python helper goes one step further and creates the environment if it does not exist): | |||
.envrc | |||
layout python python3.12 | |||
More examples: | |||
.envrc | |||
export UV_PROJECT_ENVIRONMENT="$PWD/.venv" | |||
source "$UV_PROJECT_ENVIRONMENT/bin/activate" | |||
== warning == | |||
direnv: error /home/user/.src/project/.envrc is blocked. Run `direnv allow` to approve its content | |||
Latest revision as of 01:28, 18 November 2026
Loads variables from .envrc on cd into a directory and unloads them on cd out
https://pydevtools.com/handbook/reference/direnv/
sudo apt install direnv
# bash (~/.bashrc) eval "$(direnv hook bash)"
Allow config file:
direnv allow .
default env file::
.envrc full bash script style
Only if enabled in config:
.env static key=var pairs
Example sourcing a python environment:
.envrc source .venv/bin/activate
Built in python helper example (The built-in layout python helper goes one step further and creates the environment if it does not exist):
.envrc layout python python3.12
More examples:
.envrc export UV_PROJECT_ENVIRONMENT="$PWD/.venv" source "$UV_PROJECT_ENVIRONMENT/bin/activate"
warning
direnv: error /home/user/.src/project/.envrc is blocked. Run `direnv allow` to approve its content