Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search both current directory and repo root #7

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions conf.d/venv.fish
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,18 @@
function __auto_source_venv --on-variable PWD --description "Activate/Deactivate virtualenv on directory change"
status --is-command-substitution; and return

# Check if we are inside a git repository
# Searched directories are the current directory, and the root of the current git repo if applicable
set dirs (pwd)
if git rev-parse --show-toplevel &>/dev/null
set dir (realpath (git rev-parse --show-toplevel))
else
set dir (pwd)
set -a dirs (realpath (git rev-parse --show-toplevel))
end

# Find a virtual environment in the directory
# Scan directories for a fish-compatible virtual environment
set VENV_DIR_NAMES env .env venv .venv
for venv_dir in $dir/$VENV_DIR_NAMES
if test -e "$venv_dir/bin/activate.fish"
break
end
for venv_dir in $dirs/$VENV_DIR_NAMES
if test -e "$venv_dir/bin/activate.fish"
break
end
end

# Activate venv if it was found and not activated before
Expand Down