feat(revamp): add zsh and neovim configs, add an install script and a dependencies list

This commit is contained in:
2026-04-20 12:17:46 +02:00
parent f9f5b1e184
commit 27b1db55df
227 changed files with 13985 additions and 0 deletions
@@ -0,0 +1,169 @@
# Python
Enables local Python and local Python package installation.
## Settings
This module supports virtual environments from conda and
[_virtualenvwrapper_][2]. By default, only _virtualenvwrapper_ is enabled. To
disable _virtualenvwrapper_, add the following to
_`${ZDOTDIR:-$HOME}/.zpreztorc`_.
```sh
zstyle ':prezto:module:python:virtualenv' initialize 'no'
```
Conda support can be enabled by adding the following to
_`${ZDOTDIR:-$HOME}/.zpreztorc`_.
```sh
zstyle ':prezto:module:python' conda-init 'on'
```
Caution: using conda and virtualenvwrapper at the same time may cause conflicts.
## Local Python Installation
[_pyenv_][4] builds and installs multiple Python versions locally in the home
directory.
This module prepends the _pyenv_ directory to the path variable to enable the
execution of `pyenv`.
### Usage
Install Python versions with `pyenv install` into _`~/.pyenv/versions`_.
This will be loaded automatically if pyenv is installed to `$PYENV_ROOT`,
_`~/.pyenv`_, or if the `pyenv` command is on the path. By default, `PYENV_ROOT`
is set to _`$HOME/.pyenv`_. You can set it to an alternate location and export
it in [_`${ZDOTDIR:-$HOME}/.zshenv`_][6].
## Local Package Installation
Since version 2.6, Python supports per user package installation, as defined in
[PEP 370][1].
This module prepends per user site directories to the relevant path variables
to enable the execution of user installed scripts and the reading of
documentation.
### Usage
Install packages into the per user site directory with `pip install --user`.
## virtualenvwrapper
[_virtualenvwrapper_][2] is a frontend to the popular [_virtualenv_][3] utility.
`virtualenv` creates isolated Python environments and `virtualenvwrapper`
provides convenient shell functions to create, switch, and manage them.
### Usage
Install `virtualenvwrapper`.
Virtual environments are stored in _`~/.virtualenvs`_.
There are configuration variables that have to be set to enable certain
features. If you wish to use these features, export the variables in
[_`${ZDOTDIR:-$HOME}/.zshenv`_][6].
The variable `$PROJECT_HOME` tells `virtualenvwrapper` where to place project
working directories. It must be set and the directory created before `mkproject`
is used. Replace _Developer_ with your projects directory.
```sh
export PROJECT_HOME="$HOME/Developer"
```
The variable `VIRTUALENVWRAPPER_PYTHON` tells `virtualenvwrapper` to use the
specified full path of the `python` interpreter overriding the `$PATH` search.
```sh
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python
```
The variable `VIRTUALENVWRAPPER_VIRTUALENV` tells `virtualenvwrapper` to use the
specified full path of `virtualenv` binary overriding the `$PATH` search.
```sh
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
```
The variable `$VIRTUALENVWRAPPER_VIRTUALENV_ARGS` tells `virtualenvwrapper` what
arguments to pass to `virtualenv`. For example, set the value to
`--system-site-packages` to ensure that all new environments have access to the
system site-packages directory.
```sh
export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--system-site-packages'
```
### Additional Options
There is a hook to enable auto-switching to virtualenvs when switching into a
directory where the root of the project matches a virtualenv name.
This can be enabled with:
```sh
zstyle ':prezto:module:python:virtualenv' auto-switch 'yes'
```
`virtualenvwrapper` is automatically initialized if pre-requisites are met
(`$VIRTUALENVWRAPPER_VIRTUALENV` is explicitly set or `virtualenv` is in
`$PATH`). This can be disabled with:
```sh
zstyle ':prezto:module:python:virtualenv' initialize 'no'
```
## Aliases
Aliases are enabled by default. To disable them, add the following to
_`${ZDOTDIR:-$HOME}/.zpreztorc`_.
```sh
zstyle ':prezto:module:python:alias' skip 'yes'
```
- `py` is short for `python`.
- `py2` is short for `python2`.
- `py3` is short for `python3`.
## Functions
- `python-info` exposes information about the Python environment via the
`$python_info` associative array.
## Theming
To display the name of the current virtual environment in a prompt, define the
following style in the `prompt_name_setup` function.
```sh
# %v - virtualenv name.
zstyle ':prezto:module:python:info:virtualenv' format 'virtualenv:%v'
```
Then add `$python_info[virtualenv]` to `$PROMPT` or `$RPROMPT` and call
`python-info` in the `prompt_name_preexec` hook function.
Similarly, you can use `:prezto:module:python:info:version:format` with `%v` for
the version and add `$python_info[version]` to your prompt for the current
python version.
## Authors
_The authors of this module should be contacted via the [issue tracker][5]._
- [Sorin Ionescu](https://github.com/sorin-ionescu)
- [Sebastian Wiesner](https://github.com/lunaryorn)
[1]: https://www.python.org/dev/peps/pep-0370/
[2]: https://www.doughellmann.com/projects/virtualenvwrapper/
[3]: https://pypi.org/project/virtualenv/
[4]: https://github.com/yyuu/pyenv
[5]: https://github.com/sorin-ionescu/prezto/issues
[6]: ../../runcoms#zshenv
@@ -0,0 +1,53 @@
#
# Exposes information about the Python environment via the $python_info
# associative array.
#
# Authors:
# Sorin Ionescu <sorin.ionescu@gmail.com>
# Patrick Bos <egpbos@gmail.com>
#
# function python-info {
local virtualenv_format
local virtualenv_formatted
local version_format
local version_formatted
local version
# Clean up previous $python_info.
unset python_info
typeset -gA python_info
# Grab the styling we might have to do
zstyle -s ':prezto:module:python:info:virtualenv' format 'virtualenv_format'
zstyle -s ':prezto:module:python:info:version' format 'version_format'
# Format virtualenv.
if [[ -n "$virtualenv_format" ]]; then
if [[ -n "$VIRTUAL_ENV" ]]; then
zformat -f virtualenv_formatted "$virtualenv_format" "v:${VIRTUAL_ENV:t}"
python_info[virtualenv]="$virtualenv_formatted"
fi
# Do the same for Conda virtual environments
if [[ -n "$CONDA_DEFAULT_ENV" ]]; then
zformat -f virtualenv_formatted "$virtualenv_format" "v:${CONDA_DEFAULT_ENV:t}"
python_info[virtualenv]="$virtualenv_formatted"
fi
fi
if [[ -n "$version_format" ]]; then
if (( $+commands[pyenv] )); then
version="${"$(pyenv version)"%% *}"
elif (( $+commands[python] )); then
version="${$(python3 --version)#Python }"
fi
if [[ -n "$version" && "$version" != "system" ]]; then
zformat -f version_formatted "$version_format" "v:$version"
python_info[version]="$version_formatted"
fi
fi
# }
+173
View File
@@ -0,0 +1,173 @@
#
# Enables local Python package installation.
#
# Authors:
# Sorin Ionescu <sorin.ionescu@gmail.com>
# Sebastian Wiesner <lunaryorn@googlemail.com>
# Patrick Bos <egpbos@gmail.com>
# Indrajit Raychaudhuri <irc@indrajit.com>
#
#
# Options
#
setopt EXTENDED_GLOB
# Load dependencies.
pmodload 'helper'
# Load manually installed or package manager installed pyenv into the shell
# session.
if [[ -s "${local_pyenv::=${PYENV_ROOT:-$HOME/.pyenv}/bin/pyenv}" ]] \
|| (( $+commands[pyenv] )); then
# Ensure manually installed pyenv is added to path when present.
[[ -s $local_pyenv ]] && path=($local_pyenv:h $path)
# Load pyenv into the shell session.
eval "$(pyenv init - zsh)"
# Prepend PEP 370 per user site packages directory, which defaults to
# ~/Library/Python on macOS and ~/.local elsewhere, to PATH. The
# path can be overridden using PYTHONUSERBASE.
else
if [[ -n "$PYTHONUSERBASE" ]]; then
path=($PYTHONUSERBASE/bin(N) $path)
elif is-darwin; then
path=($HOME/Library/Python/*/bin(N) $path)
else
# This is subject to change.
path=($HOME/.local/bin(N) $path)
fi
fi
unset local_pyenv
# Return if requirements are not found.
if (( ! $+commands[(i)python[0-9.]#] && ! $+functions[pyenv] && ! $+commands[conda] )); then
return 1
fi
function _python-workon-cwd {
# Check if this is a Git repo.
local GIT_REPO_ROOT="$(git rev-parse --show-toplevel 2> /dev/null)"
# Get absolute path, resolving symlinks.
local PROJECT_ROOT="$PWD:A"
while [[ "$PROJECT_ROOT" != "/" && ! -e "$PROJECT_ROOT/.venv" \
&& ! -d "$PROJECT_ROOT/.git" && "$PROJECT_ROOT" != "$GIT_REPO_ROOT" ]]; do
PROJECT_ROOT="$PROJECT_ROOT:h"
done
if [[ $PROJECT_ROOT == "/" ]]; then
PROJECT_ROOT="."
fi
# Check for virtualenv name override.
local ENV_NAME=""
if [[ -f "$PROJECT_ROOT/.venv" ]]; then
ENV_NAME="$(<$PROJECT_ROOT/.venv)"
elif [[ -f "$PROJECT_ROOT/.venv/bin/activate" ]]; then
ENV_NAME="$PROJECT_ROOT/.venv"
elif [[ $PROJECT_ROOT != "." ]]; then
ENV_NAME="$PROJECT_ROOT:t"
fi
if [[ -n $CD_VIRTUAL_ENV && "$ENV_NAME" != "$CD_VIRTUAL_ENV" ]]; then
# We've just left the repo, deactivate the environment.
# Note: this only happens if the virtualenv was activated automatically.
deactivate && unset CD_VIRTUAL_ENV
fi
if [[ $ENV_NAME != "" ]]; then
# Activate the environment only if it is not already active.
if [[ "$VIRTUAL_ENV" != "$WORKON_HOME/$ENV_NAME" ]]; then
if [[ -n "$WORKON_HOME" && -e "$WORKON_HOME/$ENV_NAME/bin/activate" ]]; then
workon "$ENV_NAME" && export CD_VIRTUAL_ENV="$ENV_NAME"
elif [[ -e "$ENV_NAME/bin/activate" ]]; then
source $ENV_NAME/bin/activate && export CD_VIRTUAL_ENV="$ENV_NAME"
fi
fi
fi
}
# Load auto workon cwd hook.
if zstyle -t ':prezto:module:python:virtualenv' auto-switch; then
# Auto workon when changing directory.
autoload -Uz add-zsh-hook
add-zsh-hook chpwd _python-workon-cwd
fi
# Load virtualenvwrapper into the shell session, if pre-requisites are met
# and unless explicitly requested not to
if (( $+VIRTUALENVWRAPPER_VIRTUALENV || $+commands[virtualenv] )) \
&& zstyle -T ':prezto:module:python:virtualenv' initialize ; then
# Set the directory where virtual environments are stored.
export WORKON_HOME="${WORKON_HOME:-$HOME/.virtualenvs}"
# Disable the virtualenv prompt. Note that we use the magic value used by the
# pure prompt because there's some additional logic in that prompt which tries
# to figure out if a user set this variable and disable the python portion of
# that prompt based on it which is the exact opposite of what we want to do.
export VIRTUAL_ENV_DISABLE_PROMPT=12
# Create a sorted array of available virtualenv related 'pyenv' commands to
# look for plugins of interest. Scanning shell '$path' isn't enough as they
# can exist in 'pyenv' synthesized paths (e.g., '~/.pyenv/plugins') instead.
local -a pyenv_plugins
local pyenv_virtualenvwrapper_plugin_found
if (( $+commands[pyenv] )); then
pyenv_plugins=(${(@oM)${(f)"$(pyenv commands --no-sh 2> /dev/null)"}:#virtualenv*})
# Optionally activate 'virtualenv-init' plugin when available.
if (( $pyenv_plugins[(i)virtualenv-init] <= $#pyenv_plugins )); then
eval "$(pyenv virtualenv-init - zsh)"
fi
# Optionally activate 'virtualenvwrapper' plugin when available.
if (( $pyenv_plugins[(i)virtualenvwrapper(_lazy|)] <= $#pyenv_plugins )); then
pyenv "$pyenv_plugins[(R)virtualenvwrapper(_lazy|)]"
pyenv_virtualenvwrapper_plugin_found="true"
fi
unset pyenv_plugins
fi
if [[ $pyenv_virtualenvwrapper_plugin_found != "true" ]]; then
# Fallback to standard 'virtualenvwrapper' if 'python' is available in '$path'.
if (( ! $+VIRTUALENVWRAPPER_PYTHON )) && (( $+commands[(i)python[0-9.]#] )); then
VIRTUALENVWRAPPER_PYTHON=$commands[(i)python[0-9.]#]
fi
virtualenvwrapper_sources=(
${(@Ov)commands[(I)virtualenvwrapper(_lazy|).sh]}
/usr/share/virtualenvwrapper/virtualenvwrapper(_lazy|).sh(OnN)
)
if (( $#virtualenvwrapper_sources )); then
source "$virtualenvwrapper_sources[1]"
fi
unset virtualenvwrapper_sources
fi
unset pyenv_virtualenvwrapper_plugin_found
fi
# Load conda into the shell session, if requested.
zstyle -T ':prezto:module:python' conda-init
if (( $? && $+commands[conda] )); then
if (( $(conda ..changeps1) )); then
echo "To make sure Conda doesn't change your prompt (should do that in the prompt module) run:\n conda config --set changeps1 false"
# TODO:
# We could just run this ourselves. In an exit hook
# (add zsh-hook zshexit [(anonymous) function]) we could then set it back
# to the way it was before we changed it. However, I'm not sure if this is
# exception safe, so left it like this for now.
fi
fi
#
# Aliases
#
if ! zstyle -t ':prezto:module:python:alias' skip; then
alias py='python'
alias py2='python2'
alias py3='python3'
fi