-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improvements to install_packages.sh, enable bells in tmux, add f…
…ish cd-override with check_and_activate_venv
- Loading branch information
Showing
7 changed files
with
84 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
function cd | ||
# Call the builtin cd function | ||
builtin cd $argv | ||
|
||
# After changing directory, check and activate venv if necessary | ||
check_and_activate_venv | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
function check_and_activate_venv --description 'Check for venv or Poetry env and activate if found' --on-variable PWD | ||
# Guard against multiple executions | ||
if set -q __VENV_ACTIVATION_IN_PROGRESS | ||
return | ||
end | ||
set -g __VENV_ACTIVATION_IN_PROGRESS 1 | ||
|
||
set -l venv_dir | ||
set -l poetry_env | ||
set -l current_venv $VIRTUAL_ENV | ||
set -l current_dir $PWD | ||
|
||
# Check current directory and its parents for venv or pyproject.toml | ||
set -l check_dir $current_dir | ||
while test "$check_dir" != "/" | ||
if test -d "$check_dir/venv" | ||
set venv_dir "$check_dir/venv" | ||
break | ||
else if test -f "$check_dir/pyproject.toml" | ||
set poetry_env (cd "$check_dir" && poetry env info --path 2>/dev/null) | ||
break | ||
end | ||
set check_dir (dirname "$check_dir") | ||
end | ||
|
||
# Determine the new environment | ||
set -l new_env | ||
if test -n "$venv_dir" | ||
set new_env "$venv_dir" | ||
else if test -n "$poetry_env" | ||
set new_env "$poetry_env" | ||
end | ||
|
||
# Check if we need to change the environment | ||
if test -n "$new_env" -a "$new_env" != "$current_venv" | ||
if test -n "$current_venv" | ||
echo "Deactivating current environment: $current_venv" | ||
deactivate | ||
end | ||
echo "Activating environment: $new_env" | ||
source "$new_env/bin/activate.fish" | ||
else if test -z "$new_env" -a -n "$current_venv" | ||
echo "Deactivating environment: $current_venv" | ||
deactivate | ||
end | ||
|
||
# Clean up | ||
set -e __VENV_ACTIVATION_IN_PROGRESS | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters