Linux/direnv: Difference between revisions

From Omnia
Jump to navigation Jump to search
(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
 
Line 7: Line 7:
  # bash (~/.bashrc)
  # bash (~/.bashrc)
  eval "$(direnv hook bash)"
  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

Latest revision as of 21:58, 7 October 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)"


.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