chore: new architecture

This commit is contained in:
Adrien Waksberg 2025-05-02 11:49:19 +02:00
commit 09d10041d2
5 changed files with 67 additions and 30 deletions

View file

@ -1,25 +0,0 @@
autoload -U add-zsh-hook
change_python_venv() {
local _p=$(pwd)
local _ps="${_p}"
while [[ "${_p}" != "${HOME}" ]] && [[ "${_p}" != "/" ]]; do
_p="${_p:h}"
_ps="${_ps} ${_p}"
done
for _p in ${(z)_ps}; do
local _venv_config=$(find "${_p}" -maxdepth 2 -mindepth 2 -name pyvenv.cfg 2>/dev/null | head -n1)
if [[ ${_venv_config} != "" ]]; then
local _venv_path="${_venv_config:h}"
source "${_venv_path}/bin/activate"
break
fi
done
if [[ "${VIRTUAL_ENV}" == "" ]]; then
source "${DEFAULT_PYTHON_VENV}/bin/activate"
fi
}
add-zsh-hook chpwd change_python_venv

View file

@ -1,10 +1,10 @@
HISTSIZE=1000
SAVEHIST=1000
HISTFILE=~/.zsh_history
DEFAULT_PYTHON_VENV="${HOME}/.local/python"
source "${0:h}/variables.zsh"
for plugin in $(ls -1 "${0:h}/plugins"); do
source "${0:h}/plugins/${plugin}"
done
source "${0:h}/aliases.zsh"
source "${0:h}/functions.zsh"
source "${0:h}/prompt.zsh"
source "${0:h}/completion.zsh"
source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh

33
plugins/git.zsh Normal file
View file

@ -0,0 +1,33 @@
function __git_prompt_git() {
GIT_OPTIONAL_LOCKS=0 command git "$@"
}
function __git_sync_info() {
local behind
local ahead
if git rev-parse --is-inside-work-tree &>/dev/null; then
local branch=$(git_current_branch)
IFS=: read behind ahead <<<"$(git rev-list --left-right --count ${branch}...origin/${branch} 2>/dev/null | sed 's|^\([0-9]\+\)\s\+\([0-9]\+\)|\1:\2|')"
if [[ "${ahead}" != "0" ]] || [[ "${behind}" != "0" ]]; then
echo "%{$fg[yellow]%}%1{±%}"
fi
fi
}
function git_prompt_info() {
if ! __git_prompt_git rev-parse --git-dir &> /dev/null ; then
return 0
fi
echo "%{$reset_color%}\ue725 on %{$fg[green]%}$(git_current_branch)$(__git_sync_info)%{$reset_color%} "
}
function git_current_branch() {
local ref
ref=$(__git_prompt_git symbolic-ref --quiet HEAD 2> /dev/null)
local ret=$?
if [[ $ret != 0 ]]; then
[[ $ret == 128 ]] && return # no git repo.
ref=$(__git_prompt_git rev-parse --short HEAD 2> /dev/null) || return
fi
echo ${ref#refs/heads/}
}

25
plugins/python.zsh Normal file
View file

@ -0,0 +1,25 @@
autoload -U add-zsh-hook
add-zsh-hook chpwd __python_change_venv
function __python_change_venv() {
local _path=$(pwd)
local _paths="${_path}"
while [[ "${_path}" != "${HOME}" ]] && [[ "${_path}" != "/" ]]; do
_path="${_path:h}"
_paths="${_paths} ${_path}"
done
for _p in ${(z)_paths}; do
local _venv_config=$(find "${_path}" -maxdepth 2 -mindepth 2 -name pyvenv.cfg 2>/dev/null | head -n1)
if [[ ${_venv_config} != "" ]]; then
local _venv_path="${_venv_config:h}"
source "${_venv_path}/bin/activate"
break
fi
done
if [[ "${VIRTUAL_ENV}" == "" ]]; then
source "${DEFAULT_PYTHON_VENV}/bin/activate"
fi
}

4
variables.zsh Normal file
View file

@ -0,0 +1,4 @@
HISTSIZE=1000
SAVEHIST=1000
HISTFILE=~/.zsh_history
DEFAULT_PYTHON_VENV="${HOME}/.local/python"