Added venv command
David Blume

David Blume commited on 2021-04-30 21:32:52
Showing 1 changed files, with 21 additions and 0 deletions.

... ...
@@ -100,6 +100,27 @@ concept() {
100 100
     apropos -s 7 . | awk '!/iso|latin/ {print $1}' | shuf -n 1 | pee "xargs echo man 7" "xargs man 7"
101 101
 }
102 102
 
103
+venv() {
104
+    # From https://twitter.com/gvanrossum/status/1319328122618048514
105
+    if [ -n "$1" ]; then
106
+        VENV=~/venv-$1
107
+        if [ -f $VENV/bin/activate ]; then
108
+            if hash deactivate 2>/dev/null; then
109
+                deactivate
110
+            fi
111
+            source $VENV/bin/activate
112
+        else
113
+            echo "Creating $1 at $VENV"
114
+            python3 -m venv $VENV
115
+            source $VENV/bin/activate
116
+        fi
117
+    else
118
+        if hash deactivate 2>/dev/null; then
119
+            deactivate
120
+        fi
121
+    fi
122
+}
123
+
103 124
 # https://unix.stackexchange.com/questions/1288/preserve-bash-history-in-multiple-terminal-windows
104 125
 HISTCONTROL=ignoredups:erasedups
105 126
 HISTIGNORE="&:ls:[bf]g:exit:pwd:clear"
106 127