From dd7de9628e82bdbaa0396741794f8ca880455a64 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Thu, 30 Mar 2023 10:39:13 -0700 Subject: [PATCH] [zsh] Make init_env_python a function inside of its script file --- zsh/func/init_env_python | 46 +++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/zsh/func/init_env_python b/zsh/func/init_env_python index 5883b3e..e524c34 100644 --- a/zsh/func/init_env_python +++ b/zsh/func/init_env_python @@ -1,28 +1,30 @@ -#!/usr/bin/env zsh # Eryn Wells -local pythonRoot -local python27SitePackages +autoload -Uz prepend_to_path -pythonRoot="$HOME/Library/Python" -if [[ -d "$pythonRoot" ]]; then - for f in `ls "$pythonRoot"`; do - prepend_to_path "$pythonRoot/$f/bin" - done -fi - -python27SitePackages="$pythonroot/2.7/lib/python/site-packages" -if [[ -d "$python27SitePackages" ]]; then - if [[ ! -z $PYTHONPATH ]]; then - PYTHONPATH=$python27SitePackages:$PYTHONPATH - else - PYTHONPATH=$python27SitePackages +init_env_python() { + local pythonRoot="$HOME/Library/Python" + if [[ -d "$pythonRoot" ]]; then + for f in "$pythonRoot/*"; do + prepend_to_path "$f/bin" + done fi -fi -export PYTHONPATH + local python27SitePackages="$pythonroot/2.7/lib/python/site-packages" + if [[ -d "$python27SitePackages" ]]; then + if [[ ! -z $PYTHONPATH ]]; then + PYTHONPATH=$python27SitePackages:$PYTHONPATH + else + PYTHONPATH=$python27SitePackages + fi + fi -if which virtualenvwrapper.sh &> /dev/null; then - export WORKON_HOME="$HOME/src/py/.envs" - source `which virtualenvwrapper.sh` -fi + export PYTHONPATH + + if which virtualenvwrapper.sh &> /dev/null; then + export WORKON_HOME="$HOME/src/py/.envs" + source `which virtualenvwrapper.sh` + fi +} + +init_env_python "$@"