Skip to content

Commit 258f7f7

Browse files
committed
Improve zsh startup and prompt timing
1 parent bd50955 commit 258f7f7

File tree

8 files changed

+65
-48
lines changed

8 files changed

+65
-48
lines changed

dot_config/starship.toml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ continuation_prompt = "[▸▹ ](overlay1)"
1717
format = """$username$hostname$container$directory$git_branch$git_status$git_state $character"""
1818

1919
# Right side: metadata only (startup/duration/time)
20-
right_format = """$custom$cmd_duration$time"""
20+
right_format = """${env_var.ZSH_STARTUP_MS}$cmd_duration$time"""
2121

2222
# =============================================================================
2323
# Character Module (Runes!)
@@ -322,14 +322,12 @@ Void = " "
322322
Windows = "󰍲 "
323323

324324
# =============================================================================
325-
# Custom Modules
325+
# Environment Modules
326326
# =============================================================================
327-
[custom.startup]
328-
command = "echo ${ZSH_STARTUP_MS}ms"
329-
when = '[ -n "$ZSH_STARTUP_MS" ]'
330-
format = "[󱎫 $output]($style) "
327+
[env_var.ZSH_STARTUP_MS]
328+
variable = "ZSH_STARTUP_MS"
329+
format = "[󱎫 ${env_value}ms]($style) "
331330
style = "overlay1"
332-
shell = ["sh"]
333331

334332
# =============================================================================
335333
# Color Palette (must be at the end of the file)

dot_config/zsh/20-plugins.zsh

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
STARSHIP_PROMPT_NEED_NEWLINE=false
77
zstyle ':zephyr:plugin:prompt' theme 'starship'
88
zstyle ':zephyr:plugin:prompt' use-cache yes
9+
zstyle ':zephyr:plugin:prompt' immediate yes
10+
11+
# Completion configuration
12+
zstyle ':zephyr:plugin:completion' use-cache yes
13+
zstyle ':zephyr:plugin:completion' immediate yes
914

1015
# Magic enter configuration (must be before magic-enter plugin loads)
1116
MAGIC_ENTER_GIT_COMMAND="git status -u ."
@@ -18,21 +23,25 @@ ZSH_AUTOSUGGEST_MANUAL_REBIND=1
1823

1924
# Set ANTIDOTE_HOME default if not set (Homebrew, then git clone fallback)
2025
if [[ -z "$ANTIDOTE_HOME" ]]; then
21-
if [[ -d "${HOMEBREW_PREFIX:-/opt/homebrew}/opt/antidote/share/antidote" ]]; then
22-
ANTIDOTE_HOME="${HOMEBREW_PREFIX:-/opt/homebrew}/opt/antidote/share/antidote"
23-
else
24-
ANTIDOTE_HOME="${ZDOTDIR:-$HOME}/.antidote"
25-
fi
26+
ANTIDOTE_HOME="${XDG_CACHE_HOME:-$HOME/Library/Caches}/antidote"
2627
fi
2728

2829
# Load antidote (with error handling)
29-
if [[ -f "$ANTIDOTE_HOME/antidote.zsh" ]]; then
30-
source "$ANTIDOTE_HOME/antidote.zsh"
30+
local antidote_script=""
31+
if [[ -f "${HOMEBREW_PREFIX:-/opt/homebrew}/opt/antidote/share/antidote/antidote.zsh" ]]; then
32+
antidote_script="${HOMEBREW_PREFIX:-/opt/homebrew}/opt/antidote/share/antidote/antidote.zsh"
33+
elif [[ -f "$ANTIDOTE_HOME/antidote.zsh" ]]; then
34+
antidote_script="$ANTIDOTE_HOME/antidote.zsh"
35+
fi
36+
37+
if [[ -n "$antidote_script" ]]; then
38+
source "$antidote_script"
3139
else
32-
print -P "%F{red}[zshrc] antidote not found at $ANTIDOTE_HOME%f" >&2
40+
print -P "%F{red}[zshrc] antidote not found (cache: $ANTIDOTE_HOME)%f" >&2
3341
print -P "%F{yellow} Install: brew install antidote%f" >&2
3442
return 1
3543
fi
44+
unset antidote_script
3645

3746
# Static plugin loading (faster than dynamic)
3847
# Regenerate with: antidote bundle < ~/.zsh_plugins.txt > ~/.zsh_plugins.zsh

dot_config/zsh/70-keybindings.zsh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ fi
4646
# Yazi file picker
4747
bindkey '^y' yazi_choose # Ctrl+y triggers yazi-based "completion"
4848

49-
# Clipboard support for zsh-shift-select (deferred with the plugin)
50-
zsh-defer -c '
49+
# Clipboard support for zsh-shift-select
50+
if bindkey -M shift-select >/dev/null 2>&1; then
5151
shift-select-copy() {
5252
if (( REGION_ACTIVE )); then
5353
zle copy-region-as-kill
@@ -58,7 +58,7 @@ zsh-defer -c '
5858
}
5959
zle -N shift-select-copy
6060
bindkey -M shift-select "^[[99;9u" shift-select-copy
61-
'
61+
fi
6262

6363
# Debug: test if Ghostty sequence arrives at all (bind in main keymap too)
6464
debug-ghostty-seq() {

dot_config/zsh/99-local.zsh.tmpl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
# =============================================================================
44
# Machine-specific configuration that shouldn't be committed
55

6-
# Nx completion (deferred)
7-
zsh-defer -c '[ -s "$HOME/.nx-completion/nx-completion.plugin.zsh" ] && source "$HOME/.nx-completion/nx-completion.plugin.zsh"'
6+
# Nx completion
7+
[[ -s "$HOME/.nx-completion/nx-completion.plugin.zsh" ]] && source "$HOME/.nx-completion/nx-completion.plugin.zsh"
88

9-
# Bun completions (deferred)
10-
zsh-defer -c '[ -s "$HOME/.bun/_bun" ] && source "$HOME/.bun/_bun"'
9+
# Bun completions
10+
[[ -s "$HOME/.bun/_bun" ]] && source "$HOME/.bun/_bun"
1111

1212
# 1Password-backed secrets
1313
# To enable 1Password integration, uncomment and adjust the op:// URIs below.
@@ -17,7 +17,7 @@ zsh-defer -c '[ -s "$HOME/.bun/_bun" ] && source "$HOME/.bun/_bun"'
1717
# Safe-chain initialization
1818
[[ -f ~/.safe-chain/scripts/init-posix.sh ]] && source ~/.safe-chain/scripts/init-posix.sh
1919

20-
# Clear startup time after first command so it only shows on the initial prompt
20+
# Clear startup time after first command so it only shows on the initial prompt.
2121
_clear_startup_time() {
2222
unset ZSH_STARTUP_MS
2323
add-zsh-hook -d preexec _clear_startup_time

dot_zprofile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
eval "$(/opt/homebrew/bin/brew shellenv)"
1+
export HOMEBREW_PREFIX="/opt/homebrew"
2+
export HOMEBREW_CELLAR="$HOMEBREW_PREFIX/Cellar"
3+
export HOMEBREW_REPOSITORY="$HOMEBREW_PREFIX"
4+
export PATH="$HOMEBREW_PREFIX/bin:$HOMEBREW_PREFIX/sbin:$PATH"
5+
export INFOPATH="$HOMEBREW_PREFIX/share/info:${INFOPATH:-}"
6+
[[ -n ${MANPATH-} ]] && export MANPATH=":${MANPATH#:}"

dot_zsh_plugins.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ mattmc3/zephyr path:plugins/prompt
44
mattmc3/zephyr path:plugins/completion
55
mattmc3/zephyr path:plugins/compstyle
66

7-
# Git aliases (deferred)
8-
ohmyzsh/ohmyzsh path:plugins/git kind:defer
7+
# Git aliases
8+
ohmyzsh/ohmyzsh path:plugins/git
99

1010
# Completions
1111
zsh-users/zsh-completions
1212

1313
# Navigation & Search (core functionality)
1414
zimfw/fzf
15-
Aloxaf/fzf-tab kind:defer
16-
jirutka/zsh-shift-select kind:defer
15+
Aloxaf/fzf-tab
16+
jirutka/zsh-shift-select
1717

18-
# Deferred plugins (loaded after prompt appears)
19-
zsh-users/zsh-autosuggestions kind:defer
20-
hlissner/zsh-autopair kind:defer
21-
MichaelAquilina/zsh-you-should-use kind:defer
22-
wfxr/forgit kind:defer
18+
# Interactive plugins
19+
zsh-users/zsh-autosuggestions
20+
hlissner/zsh-autopair
21+
MichaelAquilina/zsh-you-should-use
22+
wfxr/forgit
2323

2424
# Syntax highlighting - skip if using Warp (has built-in highlighting)
2525
# To disable: comment out the line below and regenerate plugins
26-
zdharma-continuum/fast-syntax-highlighting kind:defer
26+
zdharma-continuum/fast-syntax-highlighting

dot_zshenv.tmpl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
. "$HOME/.cargo/env"
2-
{{ if eq .chezmoi.arch "arm64" -}}
3-
ANTIDOTE_HOME="/opt/homebrew/opt/antidote/share/antidote"
4-
{{ else -}}
5-
ANTIDOTE_HOME="/usr/local/opt/antidote/share/antidote"
6-
{{ end -}}
1+
if [[ -d "$HOME/.cargo/bin" ]] && [[ ":$PATH:" != *":$HOME/.cargo/bin:"* ]]; then
2+
export PATH="$HOME/.cargo/bin:$PATH"
3+
fi
4+
ANTIDOTE_HOME="${XDG_CACHE_HOME:-$HOME/Library/Caches}/antidote"
5+
6+
# Record interactive shell startup from the earliest user startup file.
7+
if [[ -o interactive ]]; then
8+
zmodload zsh/datetime 2>/dev/null
9+
typeset -gF _ZSH_START_REAL=$EPOCHREALTIME
10+
fi

dot_zshrc

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@
44
# Modular config loaded from ~/.config/zsh/
55
# To check dependencies: zsh-check-deps
66

7-
# Record startup start time (nanoseconds)
8-
zmodload zsh/datetime
9-
typeset -gF _ZSH_START_REAL=$EPOCHREALTIME
10-
117
# Source all config files in order
128
for config in ~/.config/zsh/[0-9]*.zsh(N); do
139
source "$config"
1410
done
1511
unset config
1612

17-
# Calculate startup duration and export for starship
18-
export ZSH_STARTUP_MS=$(( (EPOCHREALTIME - _ZSH_START_REAL) * 1000 ))
19-
ZSH_STARTUP_MS=${ZSH_STARTUP_MS%%.*}
20-
unset _ZSH_START_REAL
13+
# Flush any remaining Zephyr post-zshrc hooks before the first prompt.
14+
(( $+functions[run_post_zshrc] )) && run_post_zshrc
15+
16+
# Finalize startup timing after all startup hooks have run.
17+
if [[ -n "${_ZSH_START_REAL-}" ]]; then
18+
export ZSH_STARTUP_MS=$(( (EPOCHREALTIME - _ZSH_START_REAL) * 1000 ))
19+
ZSH_STARTUP_MS=${ZSH_STARTUP_MS%%.*}
20+
unset _ZSH_START_REAL
21+
fi

0 commit comments

Comments
 (0)