Skip to content

Instantly share code, notes, and snippets.

@romainmartinez
Created January 23, 2024 18:19
Show Gist options
  • Save romainmartinez/272e9cc530fb1ab5b929e4d94bba66b9 to your computer and use it in GitHub Desktop.
Save romainmartinez/272e9cc530fb1ab5b929e4d94bba66b9 to your computer and use it in GitHub Desktop.
This Fish shell script automatically activates and deactivates Conda environments based on the presence of an environment.yml file in the current directory, with efficient parsing and user-friendly, emoji-enhanced feedback.
function auto_activate_conda --on-variable PWD
if test -f environment.yml
set env_name (awk '/name:/ {print $2; exit}' environment.yml)
if test -n "$env_name"
conda activate $env_name
echo -e (set_color green)"✅ Activated Conda environment: $env_name"(set_color normal)
set -g last_conda_env_dir $PWD
end
else
if test -n "$last_conda_env_dir"; and test $PWD != $last_conda_env_dir
conda deactivate
echo -e (set_color red)"❌ Deactivated Conda environment"(set_color normal)
set -e last_conda_env_dir
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment