-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathzshrc
More file actions
executable file
·94 lines (85 loc) · 3.15 KB
/
zshrc
File metadata and controls
executable file
·94 lines (85 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env zsh
export ZCACHE_DIR="${ZCACHE_DIR:-$HOME/.zcache}"
if [[ -f "$ZCACHE_DIR/env.zsh" ]]; then
source "$ZCACHE_DIR/env.zsh"
else
[[ -d "$ZCACHE_DIR" ]] || mkdir -p "$ZCACHE_DIR"
if [ -z "$CPUCORES" ]; then
if (($+commands[nproc])); then
export CPUCORES="$(nproc)"
else
export CPUCORES="$(getconf _NPROCESSORS_ONLN)"
fi
fi
# Determine DOTFILES_DIR
export GIT_USER=${GIT_USER:-kpango}
if [ -z "$DOTFILES_DIR" ]; then
DOTFILE_URL="github.com/$GIT_USER/dotfiles"
if [ -d "$HOME/go/src/$DOTFILE_URL" ]; then
export DOTFILES_DIR="$HOME/go/src/$DOTFILE_URL"
elif [ -d "$HOME/ghq/$DOTFILE_URL" ]; then
export DOTFILES_DIR="$HOME/ghq/$DOTFILE_URL"
elif (($+commands[ghq])); then
export DOTFILES_DIR="$(ghq root)/$DOTFILE_URL"
else
export DOTFILES_DIR="$HOME/dotfiles"
fi
fi
fpath=("$DOTFILES_DIR/zfunc" $fpath)
autoload -Uz _zcache_eval
_gen_env() {
echo "export CPUCORES=\"$CPUCORES\""
echo "export GIT_USER=\"$GIT_USER\""
echo "export DOTFILES_DIR=\"$DOTFILES_DIR\""
if (($+commands[tmux])); then
echo "export HAS_TMUX=1"
fi
if (($+commands[ghostty])); then
echo "export TERMCMD=\"ghostty -e \$SHELL -c tmux -S /tmp/tmux.sock -q has-session && exec tmux -S /tmp/tmux.sock -2 attach-session -d || exec tmux -S /tmp/tmux.sock -2 new-session -n\$USER -s\$USER@\$HOST\""
elif (($+commands[alacritty])); then
echo "export TERMCMD=\"alacritty -e \$SHELL -c tmux -S /tmp/tmux.sock -q has-session && exec tmux -S /tmp/tmux.sock -2 attach-session -d || exec tmux -S /tmp/tmux.sock -2 new-session -n\$USER -s\$USER@\$HOST\""
elif (($+commands[urxvtc])); then
echo "export TERMCMD=\"urxvtc -e \$SHELL -c tmux -S /tmp/tmux.sock -q has-session && exec tmux -S /tmp/tmux.sock -2 attach-session -d || exec tmux -S /tmp/tmux.sock -2 new-session -n\$USER -s\$USER@\$HOST\""
fi
}
_zcache_eval env 0 "_gen_env"
fi
if [[ -z "$functions[_zcache_eval]" ]]; then
fpath=("$DOTFILES_DIR/zfunc" $fpath)
autoload -Uz _zcache_eval
fi
# OS detection — file-stat + $OSTYPE only, no subprocess
if [[ -f /etc/NIXOS || -f /etc/nixos/configuration.nix ]]; then
export _ZSH_OS=nixos
elif [[ -f /etc/arch-release ]]; then
export _ZSH_OS=arch
elif [[ -f /etc/debian_version ]]; then
export _ZSH_OS=debian
elif [[ $OSTYPE = darwin* ]]; then
export _ZSH_OS=brew
else
export _ZSH_OS=generic
fi
# Combined cache: all zsh/*.zsh except OS-specific files (20-os-*.zsh)
local combined_cache="$ZCACHE_DIR/combined.zsh"
if [[ -f "$combined_cache" ]]; then
if [[ -z "$ZSH_EXECUTION_STRING" ]]; then source "$combined_cache"; fi
else
local _zsh_deps=()
for _f in "$DOTFILES_DIR/zsh"/*.zsh(N); do
[[ "${_f:t}" = 20-os-*.zsh ]] || _zsh_deps+=("$_f")
done
_zcache_eval combined 0 \
'for _f in "$DOTFILES_DIR/zsh"/*.zsh; do [[ "${_f:t}" = 20-os-*.zsh ]] || cat "$_f"; done' \
"${_zsh_deps[@]}"
fi
# OS-specific cache: only the file matching the detected OS
local _os_src="$DOTFILES_DIR/zsh/20-os-${_ZSH_OS}.zsh"
if [[ -f "$_os_src" ]]; then
local _os_cache="$ZCACHE_DIR/os-${_ZSH_OS}.zsh"
if [[ -f "$_os_cache" ]]; then
if [[ -z "$ZSH_EXECUTION_STRING" ]]; then source "$_os_cache"; fi
else
_zcache_eval "os-${_ZSH_OS}" 0 "cat '$_os_src'" "$_os_src"
fi
fi