Better naming and commentary
- ID
daf4891- date
2023-12-19 06:26:12+00:00- author
Alex Chan <alex@alexwlchan.net>- parent
ebf49f4- message
Better naming and commentary- changed files
2 files, 15 additions, 9 deletions
Changed files
config.fish (4916) → config.fish (4936)
diff --git a/config.fish b/config.fish
index 9e72281..46ee14d 100644
--- a/config.fish
+++ b/config.fish
@@ -75,8 +75,8 @@ set -g -x PIP_REQUIRE_VIRTUALENV true
#
# See https://fishshell.com/docs/current/language.html#event
#
-function __auto_auto_activate_venv --description "Auto activate/deactivate virtualenv when I change directories"
- auto_enable_venv
+function __auto_auto_activate_venv --on-variable PWD --description "Auto activate/deactivate virtualenv when I change directories"
+ auto_activate_venv
end
fish_functions/auto_activate_venv.fish (1188) → fish_functions/auto_activate_venv.fish (1314)
diff --git a/fish_functions/auto_activate_venv.fish b/fish_functions/auto_activate_venv.fish
index 9093283..bb24f1c 100644
--- a/fish_functions/auto_activate_venv.fish
+++ b/fish_functions/auto_activate_venv.fish
@@ -5,24 +5,30 @@
# name them `~/.venv`. This means it's pretty easy to work out if
# a virtualenv exists for the current directory.
function auto_activate_venv --description "Auto activate/deactivate virtualenv when I change directories"
+
+ # Get the top-level directory of the current Git repo (if any)
set REPO_ROOT (git rev-parse --show-toplevel 2>/dev/null)
- # If we're not inside a Git repo, there's no virtualenv to activate.
+ # Case #1: cd'd from a Git repo to a non-Git folder
#
- # If we're already in a virtualenv, then we want to deactivate it
- # (e.g. we've switched from a Git repo to another directory).
- # Otherwise there's nothing to do.
+ # There's no virtualenv to activate, and we want to deactivate any
+ # virtualenv which is already active.
if test -z "$REPO_ROOT"; and test -n "$VIRTUAL_ENV"
deactivate
end
- # If we're inside a Git repo, we look for the presence of .venv
- # in the root. We may already have the venv activated, in which
- # case there's nothing to do.
+ # Case #2: cd'd folders within the same Git repo
+ #
+ # The virtualenv for this Git repo is already activated, so there's
+ # nothing more to do.
if [ "$VIRTUAL_ENV" = "$REPO_ROOT/.venv" ]
return
end
+ # Case #3: cd'd from a non-Git folder into a Git repo
+ #
+ # If there's a virtualenv in the root of this repo, we should
+ # activate it now.
if [ -d "$REPO_ROOT/.venv" ]
source "$REPO_ROOT/.venv/bin/activate.fish" &>/dev/null
end