From 7e75d00c30f106a8d5d183f8b85a83c8a5f6713a Mon Sep 17 00:00:00 2001 From: Jeremy McClure Date: Sat, 1 Aug 2026 01:59:27 -0400 Subject: [PATCH] zsh: split init into zsh-init.sh --- zsh/zsh-init.sh | 104 +++++++++++++++++++++++++++++++++++++++++++ zsh/zshrc | 115 +++++------------------------------------------- 2 files changed, 115 insertions(+), 104 deletions(-) create mode 100644 zsh/zsh-init.sh diff --git a/zsh/zsh-init.sh b/zsh/zsh-init.sh new file mode 100644 index 0000000..c1b8b7b --- /dev/null +++ b/zsh/zsh-init.sh @@ -0,0 +1,104 @@ +export ZSH_CONFIG=$HOME/.config/zsh +export OHMYZSH=$ZSH_CONFIG/oh-my-zsh +export OHMYZSH_CUSTOM=$OHMYZSH/custom + +export ZSHRC_BRANCH="${ZSHRC_BRANCH:-$(cat "$ZSH_CONFIG/branch" 2>/dev/null || echo master)}" +export ZSHRC_GIT="https://git.jeremymcclure.com/jeremy/scripts/raw/branch/${ZSHRC_BRANCH}/zsh/" + +export ZSHRC_URL="$ZSHRC_GIT/zshrc" +export ZSHRC_BOOTSTRAP_URL="$ZSHRC_GIT/zshrc-bootstrap.zsh" +export ZSHRC_BOOTSTRAP_VERSION="4" +export ZSHRC_BOOTSTRAP="$ZSH_CONFIG/.bootstrapped" + +[[ -d "$HOME/Scripts" ]] && path+=("$HOME/Scripts") +[[ -d "$HOME/.local/bin" ]] && path+=("$HOME/.local/bin") +[[ -d "$HOME/AppImages" ]] && path+=("$HOME/AppImages") +[[ -d "$HOME/.opencode/bin" ]] && path+=("$HOME/.opencode/bin") + +[[ -f "$ZSH_CONFIG/zsh-functions.zsh" ]] && source "$ZSH_CONFIG/zsh-functions.zsh" + +# Bootstrap: installs missing CLI tools and oh-my-zsh plugins across distros. +if [[ ! -f "$ZSHRC_BOOTSTRAP" || "$(cat "$ZSHRC_BOOTSTRAP" 2>/dev/null)" != "$ZSHRC_BOOTSTRAP_VERSION" || "$BOOTSTRAP" == "true" ]]; then + tmp=/tmp/.zshrc_bootstrap.$$ + curl -fsSL --connect-timeout 5 --max-time 10 -o "$tmp" "$ZSHRC_BOOTSTRAP_URL" 2>/dev/null + if [[ -f "$tmp" ]]; then + zsh "$tmp" 2>/dev/null + echo "$ZSHRC_BOOTSTRAP_VERSION" > "$ZSHRC_BOOTSTRAP" + rm -f "$tmp" + fi +fi + +TMUXCONF="$HOME/.config/tmux" +BYOBUCONF="$HOME/.config/byobu" +TMUXREMOTE="$ZSHRC_GIT/tmux.conf" +if [ ! -f "$TMUXCONF/tmux.conf" ] && [ ! -f "$BYOBUCONF/.tmux.conf" ]; then + TEMP_TMUXCONF=$(mktemp) + if curl -fsSL --connect-timeout 5 --max-time 10 -o "$TEMP_TMUXCONF" "$TMUXREMOTE"; then + mkdir -p "$TMUXCONF" "$BYOBUCONF" + cp "$TEMP_TMUXCONF" "$TMUXCONF/tmux.conf" + mv "$TEMP_TMUXCONF" "$BYOBUCONF/.tmux.conf" + else + rm -f "$TEMP_TMUXCONF" + echo "Error: Failed to download tmux config from $TMUXREMOTE" >&2 + fi +fi + +export HISTFILE="$ZSH_CONFIG/history" +export ZSH_COMPDUMP="$ZSH_CONFIG/zcompdump-${HOST}-${ZSH_VERSION}" +export HISTSIZE=10000 +export SAVEHIST=10000 + +setopt SHARE_HISTORY +setopt HIST_IGNORE_DUPS +setopt HIST_IGNORE_ALL_DUPS +setopt HIST_REDUCE_BLANKS +setopt HIST_FCNTL_LOCK +setopt AUTO_CD +setopt AUTO_LIST +setopt INTERACTIVE_COMMENTS +setopt HIST_VERIFY +setopt EXTENDED_HISTORY +setopt AUTO_PUSHD +setopt PUSHD_IGNORE_DUPS +setopt PUSHD_SILENT + +ZSH_THEME="" +ENABLE_CORRECTION="false" +HIST_STAMPS="mm/dd/yyyy" + +plugins=( + git + sudo + extract + eza + history + kitty + docker + docker-compose + archlinux + encode64 + universalarchive + zsh-autosuggestions + fast-syntax-highlighting + fzf + fzf-tab + systemd + vscode + rsync + starship +) + +zstyle ':omz:update' 'mode' auto +zstyle ':omz:plugins:eza' 'dirs-first' yes +zstyle ':omz:plugins:eza' 'git-status' yes +zstyle ':omz:plugins:eza' 'header' yes +zstyle ':omz:plugins:eza' 'show-group' yes +zstyle ':omz:plugins:eza' 'icons' yes +zstyle ':omz:plugins:eza' 'color-scale' all +zstyle ':omz:plugins:eza' 'color-scale-mode' fixed +zstyle ':omz:plugins:eza' 'size-prefix' si + +zstyle ':completion:*' menu select +zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}' +zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}" +zstyle ':completion:*' special-dirs true diff --git a/zsh/zshrc b/zsh/zshrc index 13aefe2..ccd8880 100644 --- a/zsh/zshrc +++ b/zsh/zshrc @@ -1,107 +1,4 @@ -export ZSH_CONFIG=$HOME/.config/zsh -export OHMYZSH=$ZSH_CONFIG/oh-my-zsh -export OHMYZSH_CUSTOM=$OHMYZSH/custom - -export ZSHRC_BRANCH="${ZSHRC_BRANCH:-$(cat "$ZSH_CONFIG/branch" 2>/dev/null || echo master)}" -export ZSHRC_GIT="https://git.jeremymcclure.com/jeremy/scripts/raw/branch/${ZSHRC_BRANCH}/zsh/" - -export ZSHRC_URL="$ZSHRC_GIT/zshrc" -export ZSHRC_BOOTSTRAP_URL="$ZSHRC_GIT/zshrc-bootstrap.zsh" -export ZSHRC_BOOTSTRAP_VERSION="4" -export ZSHRC_BOOTSTRAP="$ZSH_CONFIG/.bootstrapped" - -[[ -d "$HOME/Scripts" ]] && path+=("$HOME/Scripts") -[[ -d "$HOME/.local/bin" ]] && path+=("$HOME/.local/bin") -[[ -d "$HOME/AppImages" ]] && path+=("$HOME/AppImages") -[[ -d "$HOME/.opencode/bin" ]] && path+=("$HOME/.opencode/bin") - -[[ -f "$ZSH_CONFIG/zsh-functions.zsh" ]] && source "$ZSH_CONFIG/zsh-functions.zsh" - -# Bootstrap: installs missing CLI tools and oh-my-zsh plugins across distros. -if [[ ! -f "$ZSHRC_BOOTSTRAP" || "$(cat "$ZSHRC_BOOTSTRAP" 2>/dev/null)" != "$ZSHRC_BOOTSTRAP_VERSION" || "$BOOTSTRAP" == "true" ]]; then - tmp=/tmp/.zshrc_bootstrap.$$ - curl -fsSL --connect-timeout 5 --max-time 10 -o "$tmp" "$ZSHRC_BOOTSTRAP_URL" 2>/dev/null - if [[ -f "$tmp" ]]; then - zsh "$tmp" 2>/dev/null - echo "$ZSHRC_BOOTSTRAP_VERSION" > "$ZSHRC_BOOTSTRAP" - rm -f "$tmp" - fi -fi - -TMUXCONF="$HOME/.config/tmux" -BYOBUCONF="$HOME/.config/byobu" -TMUXREMOTE="$ZSHRC_GIT/tmux.conf" -if [ ! -f "$TMUXCONF/tmux.conf" ] && [ ! -f "$BYOBUCONF/.tmux.conf" ]; then - TEMP_TMUXCONF=$(mktemp) - if curl -fsSL --connect-timeout 5 --max-time 10 -o "$TEMP_TMUXCONF" "$TMUXREMOTE"; then - mkdir -p "$TMUXCONF" "$BYOBUCONF" - cp "$TEMP_TMUXCONF" "$TMUXCONF/tmux.conf" - mv "$TEMP_TMUXCONF" "$BYOBUCONF/.tmux.conf" - else - rm -f "$TEMP_TMUXCONF" - echo "Error: Failed to download tmux config from $TMUXREMOTE" >&2 - fi -fi - -export HISTFILE="$ZSH_CONFIG/history" -export ZSH_COMPDUMP="$ZSH_CONFIG/zcompdump-${HOST}-${ZSH_VERSION}" -export HISTSIZE=10000 -export SAVEHIST=10000 - -setopt SHARE_HISTORY -setopt HIST_IGNORE_DUPS -setopt HIST_IGNORE_ALL_DUPS -setopt HIST_REDUCE_BLANKS -setopt HIST_FCNTL_LOCK -setopt AUTO_CD -setopt AUTO_LIST -setopt INTERACTIVE_COMMENTS -setopt HIST_VERIFY -setopt EXTENDED_HISTORY -setopt AUTO_PUSHD -setopt PUSHD_IGNORE_DUPS -setopt PUSHD_SILENT - -ZSH_THEME="" -ENABLE_CORRECTION="false" -HIST_STAMPS="mm/dd/yyyy" - -plugins=( - git - sudo - extract - eza - history - kitty - docker - docker-compose - archlinux - encode64 - universalarchive - zsh-autosuggestions - fast-syntax-highlighting - fzf - fzf-tab - systemd - vscode - rsync - starship -) - -zstyle ':omz:update' 'mode' auto -zstyle ':omz:plugins:eza' 'dirs-first' yes -zstyle ':omz:plugins:eza' 'git-status' yes -zstyle ':omz:plugins:eza' 'header' yes -zstyle ':omz:plugins:eza' 'show-group' yes -zstyle ':omz:plugins:eza' 'icons' yes -zstyle ':omz:plugins:eza' 'color-scale' all -zstyle ':omz:plugins:eza' 'color-scale-mode' fixed -zstyle ':omz:plugins:eza' 'size-prefix' si - -zstyle ':completion:*' menu select -zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}' -zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}" -zstyle ':completion:*' special-dirs true +[[ -f "$ZSH_CONFIG/zsh-init.sh" ]] && source "$ZSH_CONFIG/zsh-init.sh" source $OHMYZSH/oh-my-zsh.sh @@ -148,6 +45,16 @@ if [[ -o interactive && "$ZSHRC_UPDATE_DISABLED" != "true" ]]; then fi rm -f "$tmp" + # zsh-init + itmp=/tmp/.zsh-init.$$ + if curl -fsSL --connect-timeout 3 --max-time 8 "$ZSHRC_GIT/zsh-init.sh" -o "$itmp" 2>/dev/null \ + && [[ -f "$itmp" ]] && ! cmp -s "$itmp" "$ZSH_CONFIG/zsh-init.sh" 2>/dev/null; then + echo "Updating zsh-init..." + mv "$itmp" "$ZSH_CONFIG/zsh-init.sh" + else + rm -f "$itmp" + fi + # zsh-functions ftmp=/tmp/.zsh-functions.$$ if curl -fsSL --connect-timeout 3 --max-time 8 "$ZSHRC_GIT/zsh-functions.zsh" -o "$ftmp" 2>/dev/null \