summaryrefslogtreecommitdiff
path: root/home/.oh-my-zsh/plugins/autoenv/autoenv.plugin.zsh
diff options
context:
space:
mode:
authornavewindre <boneyaard@gmail.com>2025-07-13 06:42:05 +0200
committernavewindre <boneyaard@gmail.com>2025-07-13 06:42:05 +0200
commit02f14a9cb152561a5e44062aac79f3b700403b40 (patch)
tree2db8ebda3b7f6f8777783aeb5c60018e6e1359d8 /home/.oh-my-zsh/plugins/autoenv/autoenv.plugin.zsh
parentcbbdeb2f6b40a102a829f0c47cff052937231f00 (diff)
omz
Diffstat (limited to 'home/.oh-my-zsh/plugins/autoenv/autoenv.plugin.zsh')
-rw-r--r--home/.oh-my-zsh/plugins/autoenv/autoenv.plugin.zsh80
1 files changed, 80 insertions, 0 deletions
diff --git a/home/.oh-my-zsh/plugins/autoenv/autoenv.plugin.zsh b/home/.oh-my-zsh/plugins/autoenv/autoenv.plugin.zsh
new file mode 100644
index 0000000..2f84f0a
--- /dev/null
+++ b/home/.oh-my-zsh/plugins/autoenv/autoenv.plugin.zsh
@@ -0,0 +1,80 @@
+# Initialization: activate autoenv or report its absence
+() {
+local d autoenv_dir install_locations
+if ! type autoenv_init >/dev/null; then
+ # Check if activate.sh is in $PATH
+ if (( $+commands[activate.sh] )); then
+ autoenv_dir="${commands[activate.sh]:h}"
+ fi
+
+ # Locate autoenv installation
+ if [[ -z $autoenv_dir ]]; then
+ install_locations=(
+ ~/.autoenv
+ ~/.local/bin
+ /usr/local/opt/autoenv
+ /opt/homebrew/opt/autoenv
+ /usr/local/bin
+ /usr/share/autoenv-git
+ ~/Library/Python/bin
+ .venv/bin
+ venv/bin
+ env/bin
+ .env/bin
+ )
+ for d ( $install_locations ); do
+ if [[ -e $d/activate || -e $d/activate.sh ]]; then
+ autoenv_dir=$d
+ break
+ fi
+ done
+ fi
+
+ # Look for Homebrew path as a last resort
+ if [[ -z "$autoenv_dir" ]] && (( $+commands[brew] )); then
+ d=$(brew --prefix)/opt/autoenv
+ if [[ -e $d/activate || -e $d/activate.sh ]]; then
+ autoenv_dir=$d
+ fi
+ fi
+
+ # Complain if autoenv is not installed
+ if [[ -z $autoenv_dir ]]; then
+ cat <<END >&2
+-------- AUTOENV ---------
+Could not locate autoenv installation.
+Please check if autoenv is correctly installed.
+In the meantime the autoenv plugin is DISABLED.
+--------------------------
+END
+ return 1
+ fi
+ # Load autoenv
+ if [[ -e $autoenv_dir/activate ]]; then
+ source $autoenv_dir/activate
+ else
+ source $autoenv_dir/activate.sh
+ fi
+fi
+}
+[[ $? != 0 ]] && return $?
+
+# The use_env call below is a reusable command to activate/create a new Python
+# virtualenv, requiring only a single declarative line of code in your .env files.
+# It only performs an action if the requested virtualenv is not the current one.
+
+use_env() {
+ local venv
+ venv="$1"
+ if [[ "${VIRTUAL_ENV:t}" != "$venv" ]]; then
+ if workon | grep -q "$venv"; then
+ workon "$venv"
+ else
+ echo -n "Create virtualenv $venv now? (Yn) "
+ read answer
+ if [[ "$answer" == "Y" ]]; then
+ mkvirtualenv "$venv"
+ fi
+ fi
+ fi
+}