[ZSH] Extract shared startup modules

Keep the server entrypoint focused on server policy while moving update checks, Antidote loading, interactive defaults, and prompt sourcing into reusable modules.
This commit is contained in:
Fabian Ising
2026-07-27 10:57:11 +02:00
committed by Fabian Ising
parent 7ccb268cfb
commit 81deaa75a4
5 changed files with 142 additions and 197 deletions
+12
View File
@@ -0,0 +1,12 @@
# Callers set plugins_txt and static_file before sourcing this module.
mkdir -p "${static_file:h}"
if [[ ! -e ${ZDOTDIR:-$HOME}/.antidote ]]; then
git clone https://github.com/mattmc3/antidote.git "${ZDOTDIR:-$HOME}/.antidote"
fi
zstyle ':completion:*:ssh:*' hosts off
zstyle ':completion:*:scp:*' hosts off
zstyle ':completion:*:commands' rehash 1
source "${ZDOTDIR:-$HOME}/.antidote/antidote.zsh"
antidote load "$plugins_txt" "$static_file"
+43
View File
@@ -0,0 +1,43 @@
setopt interactivecomments
HISTSIZE=100000
SAVEHIST=100000
setopt EXTENDED_HISTORY
setopt INC_APPEND_HISTORY
setopt SHARE_HISTORY
setopt HIST_EXPIRE_DUPS_FIRST
setopt HIST_IGNORE_DUPS
setopt HIST_IGNORE_ALL_DUPS
setopt HIST_FIND_NO_DUPS
setopt HIST_IGNORE_SPACE
setopt HIST_SAVE_NO_DUPS
setopt HIST_REDUCE_BLANKS
bindkey '^q' clear-screen
(( $+commands[nvim] )) && alias vim=nvim
(( $+commands[nvim] )) && export EDITOR=nvim VISUAL=nvim
alias sudo='sudo '
alias ls='ls --color=always'
alias cgrep='grep --color=always'
alias cdiff='git diff --color-words --no-index'
delzip() {
unzip -Z -1 "$@" | xargs -I{} rm -rf {}
}
export MITMPROXY_SSLKEYLOGFILE='~/.mitmproxy/sslkeylogfile.txt'
unset ZSH_AUTOSUGGEST_USE_ASYNC
export LANG='en_US.UTF-8'
export LC_CTYPE='en_US.UTF-8'
export TIME_STYLE='long-iso'
pasteinit() {
OLD_SELF_INSERT=${${(s.:.)widgets[self-insert]}[2,3]}
zle -N self-insert url-quote-magic
}
pastefinish() {
zle -N self-insert "$OLD_SELF_INSERT"
}
zstyle :bracketed-paste-magic paste-init pasteinit
zstyle :bracketed-paste-magic paste-finish pastefinish
ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(bracketed-paste)
+3
View File
@@ -0,0 +1,3 @@
# Callers select p10k_config before sourcing this module.
ZLE_RPROMPT_INDENT=0
[[ -z "$p10k_config" || ! -f "$p10k_config" ]] || source "$p10k_config"
+61
View File
@@ -0,0 +1,61 @@
# Background repository maintenance shared by desktop and server shells.
update_dotfiles() {
local repo="$HOME/dotfiles"
local cache_dir="${ZDOTDIR:-$HOME}/.cache/zsh"
local notice_file="$cache_dir/dotfiles-update-notice"
local notice_tmp="$notice_file.$$.tmp"
local -a TO; (( $+commands[timeout] )) && TO=(timeout -k 5 15)
GIT_SSH_COMMAND='ssh -o BatchMode=yes -o ConnectTimeout=5 -o ControlMaster=no -o ControlPath=none' \
$TO git -C "$repo" fetch --quiet </dev/null 2>/dev/null || return
git -C "$repo" rev-parse --abbrev-ref '@{u}' >/dev/null 2>&1 || return
git -C "$repo" merge-base --is-ancestor '@{u}' HEAD 2>/dev/null && return
git -C "$repo" merge --ff-only --quiet '@{u}' 2>/dev/null && return
local notice="⚠ dotfiles: $(git -C "$repo" symbolic-ref --short HEAD) can't fast-forward to @{u} — run: git -C ~/dotfiles pull"
mkdir -p "$cache_dir" || return
print -r -- "$notice" >| "$notice_tmp" || return
mv -f "$notice_tmp" "$notice_file"
}
update_dotfiles &!
check_tools_repo() {
local repo branch remote mergeref remote_sha local_sha cmd notice
local cache_dir="${ZDOTDIR:-$HOME}/.cache/zsh"
local notice_file="$cache_dir/tools-update-notice"
local notice_tmp="$notice_file.$$.tmp"
local -a TO; (( $+commands[timeout] )) && TO=(timeout -k 5 10)
for repo in /opt/tools "$HOME/tools" "$HOME/tools/tools-repo"; do
local -a g=(git -c 'safe.directory=*' -C "$repo")
$g rev-parse --is-inside-work-tree >/dev/null 2>&1 || continue
branch=$($g symbolic-ref --short HEAD 2>/dev/null) || return
remote=$($g config "branch.$branch.remote" 2>/dev/null) || return
mergeref=$($g config "branch.$branch.merge" 2>/dev/null) || return
remote_sha=$(GIT_SSH_COMMAND='ssh -o BatchMode=yes -o ConnectTimeout=5 -o ControlMaster=no -o ControlPath=none' \
$TO $g ls-remote "$remote" "$mergeref" </dev/null 2>/dev/null | awk '{print $1}')
local_sha=$($g rev-parse HEAD 2>/dev/null)
[[ -n "$remote_sha" && -n "$local_sha" ]] || return
[[ "$remote_sha" == "$local_sha" ]] && return
$g merge-base --is-ancestor "$remote_sha" HEAD 2>/dev/null && return
[[ -w "$repo/.git" ]] && cmd="git -C $repo pull" || cmd="sudo git -C $repo pull"
notice="⬆ tools: updates available in $repo — run: $cmd"
mkdir -p "$cache_dir" || return
print -r -- "$notice" >| "$notice_tmp" || return
mv -f "$notice_tmp" "$notice_file"
return
done
}
check_tools_repo &!
show_update_notices() {
local cache_dir="${ZDOTDIR:-$HOME}/.cache/zsh"
local notice_file claimed_notice
for notice_file in "$cache_dir"/{dotfiles,tools}-update-notice; do
[[ -s "$notice_file" ]] || continue
claimed_notice="$notice_file.$$.show"
mv "$notice_file" "$claimed_notice" 2>/dev/null || continue
command cat "$claimed_notice"
command rm -f "$claimed_notice"
done
}
autoload -Uz add-zsh-hook
add-zsh-hook precmd show_update_notices