Skip to content

Commit 718156b

Browse files
committed
add py shell function
`py on` creates and activates a venv in $DOTFILES `py off` calls "deactivate" if you're in a venv
1 parent d7298f4 commit 718156b

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ link/.vim/plugged
1212
link/.vim/.netrwhist
1313

1414
/perl5/
15+
/venv/
1516

1617
/bin/cap-360
1718
/bin/g

source/misc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,3 +373,24 @@ faketime() {
373373
perllib() {
374374
cpanm --local-lib="$DOTFILES/perl5" local::lib && eval $(perl -I "$DOTFILES/perl5/lib/perl5/" -Mlocal::lib="$DOTFILES/perl5")
375375
}
376+
377+
py() {
378+
d="$DOTFILES/venv"
379+
[ -e bin/activate ] && d="$(pwd)"
380+
case "$1" in
381+
on)
382+
[ -z "$VIRTUAL_ENV" ] || { echo "already in $VIRTUAL_ENV, aborting" >&2; return 1; }
383+
[ -d "$d" ] || python3 -m venv "$d"
384+
. "$d/bin/activate"
385+
;;
386+
off)
387+
[ -z "$VIRTUAL_ENV" ] && { echo "not in a virtual env, aborting" >&2; return 1; }
388+
deactivate
389+
;;
390+
*)
391+
echo 'unknown command: use "on" or "off"' >&2
392+
return 1
393+
;;
394+
esac
395+
}
396+

0 commit comments

Comments
 (0)