]> arthur.barton.de Git - ax-zsh.git/commitdiff
New "virtualenv" plugin
authorAlexander Barton <alex@barton.de>
Mon, 23 Apr 2018 21:39:14 +0000 (23:39 +0200)
committerAlexander Barton <alex@barton.de>
Mon, 23 Apr 2018 21:39:14 +0000 (23:39 +0200)
plugins/virtualenv/README.md [new file with mode: 0644]
plugins/virtualenv/virtualenv.zshrc [new file with mode: 0644]

diff --git a/plugins/virtualenv/README.md b/plugins/virtualenv/README.md
new file mode 100644 (file)
index 0000000..d429142
--- /dev/null
@@ -0,0 +1,10 @@
+## virtualenv
+
+Define the `activate` function to read in (and therefore to "activate") a
+(Python) *virtual environment*, like provided by the "venv" Python module -- but
+this module is language agnostic, and can activate all environments providing an
+`activate` shell fragment in a known location.
+
+### Aliases
+
+- `activate`
diff --git a/plugins/virtualenv/virtualenv.zshrc b/plugins/virtualenv/virtualenv.zshrc
new file mode 100644 (file)
index 0000000..8545374
--- /dev/null
@@ -0,0 +1,22 @@
+# AX-ZSH: Alex' Modular ZSH Configuration
+# virtualenv: Activate an "virtual environment"
+
+function activate() {
+       for d (
+               ./bin
+               ./env/bin
+               ./venv/bin
+               ./.venv/bin
+       ); do
+               script="$d/activate"
+               test -r "$script" || continue
+
+               # Read in activation script fragment ...
+               source "$script" && return 0
+
+               echo "Failed to read script \"$script\"!" >&2
+               return 1
+       done
+       echo "No virtual environment found!" >&2
+       return 1
+}