Linux/direnv

From Omnia
Jump to navigation Jump to search

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)"


.envrc

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