Skip to content

Instantly share code, notes, and snippets.

@fisadev
Last active February 25, 2021 03:38
Show Gist options
  • Save fisadev/f6b5940ca2754deafd2b97a254c45d24 to your computer and use it in GitHub Desktop.
Save fisadev/f6b5940ca2754deafd2b97a254c45d24 to your computer and use it in GitHub Desktop.
Automagic venv for fish
# usage:
# e --> create and/or activate a virtualenv, named in a way that's unique and related to the current folder
# but stored under ~/venvs/
# e NAME --> create and/or activate a virtualenv with the specified name, stored under ~/venvs/
# you should replace `\/home\/fisa\/devel\/` (scaped text for `/home/fisa/devel/`) with the folder in which most
# of your projects live, so a venv for a project /home/fisa/devel/company_x/project_y/ will be named just
# "company_x_project_y", without the full path as part of the name. It's kind of a default prefix.
function e
if count $argv > /dev/null
set env_name $argv
else
set env_name (pwd | sed "s/\/home\/fisa\/devel\///g" | sed "s/\//_/g")
end
set env_dir ~/venvs/$env_name
if not test -d $env_dir
echo "No virtualenv named $env_name, creating a new one..."
python3 -m venv $env_dir
echo "Upgrading pip..."
$env_dir/bin/pip install pip --upgrade
echo "Done"
end
. $env_dir/bin/activate.fish
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment