#!/bin/bash set -euo pipefail # Install pyenv (Python Version Manager) if it is not already installed if command -v pyenv &> /dev/null; then echo -e "pyenv is already installed\n" else echo -e "Installing pyenv (Python Version Manager)\n" # Using the official pyenv installer (https://github.com/pyenv/pyenv-installer) curl -fsSL https://pyenv.run | bash # Load pyenv for the remainder of this script export PYENV_ROOT="$HOME/.pyenv" [[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH" eval "$(pyenv init - bash)" command -v pyenv &> /dev/null fi # OPTIONAL: Install the latest stable version of Python # Uncomment the following line if you would like to automatically install it # pyenv install 3.12.0 && pyenv global 3.12.0 # Always-on fragment: ~/.config/zsh/pyenv.zsh (sourced from ~/.zshenv) curl -fsSL https://git.miomio.moe/mio/easyzsh/raw/branch/master/patch.sh | bash -s -- zsh/pyenv # macOS path_helper runs after ~/.zshenv in login shells, so reapply pyenv afterwards. PYENV_LOGIN_HOOK='[[ -f "${XDG_CONFIG_HOME:-$HOME/.config}/zsh/pyenv.zsh" ]] && . "${XDG_CONFIG_HOME:-$HOME/.config}/zsh/pyenv.zsh"' if ! grep -Fqx "$PYENV_LOGIN_HOOK" "$HOME/.zprofile" 2>/dev/null; then [[ ! -s "$HOME/.zprofile" ]] || printf '\n' >> "$HOME/.zprofile" printf '%s\n' "$PYENV_LOGIN_HOOK" >> "$HOME/.zprofile" fi # Drop legacy interactive-only copy if present rm -f "$HOME/.config/zshrc/pyenv.zsh"