From 2fa96e8054078feae2016d922d47415eec002f6e Mon Sep 17 00:00:00 2001 From: Anton Bobov Date: Sat, 5 Aug 2023 23:35:05 +0500 Subject: [zsh] Update aliases and functions --- files/.zsh/rc/S50_functions | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'files/.zsh/rc/S50_functions') diff --git a/files/.zsh/rc/S50_functions b/files/.zsh/rc/S50_functions index 4129fd6..b9bd045 100644 --- a/files/.zsh/rc/S50_functions +++ b/files/.zsh/rc/S50_functions @@ -62,14 +62,27 @@ alias calc="noglob calc" # Take from @garybernhardt activate_virtualenv() { - for name in venv env ; do - for up in . ../.. ../../.. ; do - if [ -f $up/$name/bin/activate ] ; then - . $up/$name/bin/activate - return - fi - done + local found_location="" + for name in venv env ; do + for up in . ../.. ../../.. ; do + if [ -f "$up/$name/bin/activate" ] ; then + found_location="$up/$name/bin/activate" + break + fi done + [ -n "$found_location" ] && break + done + + if [ -z "$found_location" ] ; then + # create + read -r "answer?Virtualenv not found, create? " + if [[ "$answer" =~ ^[Yy]$ ]] ; then + virtualenv venv + activate_virtualenv + fi + else + . "$found_location" + fi } edit-which() { -- cgit v1.2.3