diff --git a/dotfiles/config/direnv/lib/python.sh b/dotfiles/config/direnv/lib/python.sh new file mode 100644 index 0000000..2bb5104 --- /dev/null +++ b/dotfiles/config/direnv/lib/python.sh @@ -0,0 +1,16 @@ +layout_python() { + local DIR_NAME="$(basename $(pwd))" + VIRTUAL_ENV="${VIRTUAL_ENV:-$(pwd)/.venv/${DIR_NAME}}" + local PYBIN="$(command -v python 2>/dev/null || command -v python3 2>/dev/null)" + if [[ -z "${PYBIN}" ]]; then + log_error "No python found!" + return 1 + fi + if [[ ! -d $VIRTUAL_ENV ]]; then + log_status "No virtual environment exists. Executing \`${PYBIN} -m venv ${VIRTUAL_ENV}\`." + "${PYBIN}" -m venv "${VIRTUAL_ENV}" + fi + + # Activate the virtual environment + . $VIRTUAL_ENV/bin/activate +} diff --git a/dotfiles/zshrc b/dotfiles/zshrc index d58b4cc..9417670 100755 --- a/dotfiles/zshrc +++ b/dotfiles/zshrc @@ -112,6 +112,8 @@ if [[ $- == *i* ]] ; then source /usr/share/virtualenvwrapper/virtualenvwrapper_lazy.sh elif test -f /usr/bin/virtualenvwrapper_lazy.sh ; then source /usr/bin/virtualenvwrapper_lazy.sh + elif test -f /opt/homebrew/bin/virtualenvwrapper_lazy.sh ; then + source /opt/homebrew/bin/virtualenvwrapper_lazy.sh fi if command ls --version >/dev/null 2>&1 ; then alias ls="$(whence -p ls) --color=auto" @@ -144,6 +146,10 @@ if [[ $- == *i* ]] ; then # History alias fullhist="history 1" alias longhist="history -1000" + # direnv if present + if command -v direnv >/dev/null 2>&1 ; then + eval "$(direnv hook zsh)" + fi fi # End interactive-only block # In case ack is named ack-grep