From 052b393621af8f7149e96c1faaf7f883d857ccce Mon Sep 17 00:00:00 2001 From: Kieran Klukas Date: Wed, 12 Aug 2026 22:54:47 -0400 Subject: [PATCH] chore: get rid of direnv hook --- modules/home/system/shell.nix | 42 ++++++++++------------------------- 1 file changed, 12 insertions(+), 30 deletions(-) diff --git a/modules/home/system/shell.nix b/modules/home/system/shell.nix index 79c8f5d..af914ba 100644 --- a/modules/home/system/shell.nix +++ b/modules/home/system/shell.nix @@ -735,45 +735,27 @@ in # chpwd hooks autoload -Uz add-zsh-hook + # Tracks which venv we activated, so a venv you sourced by hand + # is never yanked out from under you. + typeset -g _auto_venv="" + function auto_venv() { - if [[ -n "$VIRTUAL_ENV" && ! -f "$VIRTUAL_ENV/bin/activate" ]]; then - deactivate - fi - [[ -n "$VIRTUAL_ENV" ]] && return - local dir="$PWD" + local dir="$PWD" venv="" while [[ "$dir" != "/" ]]; do if [[ -f "$dir/.venv/bin/activate" ]]; then - source "$dir/.venv/bin/activate" - return - fi - dir="''${dir:h}" - done - } - - function auto_nix() { - [[ -n "$IN_NIX_SHELL" ]] && return - local dir="$PWD" - while [[ "$dir" != "/" ]]; do - if [[ -f "$dir/flake.nix" ]]; then - if [[ ! -f "$dir/.envrc" ]]; then - local arch - arch="$(nix eval --impure --expr 'builtins.currentSystem' 2>/dev/null | tr -d '"')" - if nix eval --json "$dir#devShells.$arch" \ - --apply 'x: true' >/dev/null 2>&1; then - cat > "$dir/.envrc" <<'EOF' - use flake - EOF - command direnv allow "$dir" >/dev/null 2>&1 - fi - fi - return + venv="$dir/.venv" + break fi dir="''${dir:h}" done + [[ "$VIRTUAL_ENV" == "$venv" ]] && return + [[ -n "$VIRTUAL_ENV" && "$VIRTUAL_ENV" != "$_auto_venv" ]] && return + (( $+functions[deactivate] )) && deactivate + _auto_venv="$venv" + [[ -n "$venv" ]] && source "$venv/bin/activate" } add-zsh-hook chpwd auto_venv - add-zsh-hook chpwd auto_nix # zsh-patina: Rust-based syntax highlighting (must be last) eval "$(${ -- 2.51.2