Skip to content

Commit cc976ae

Browse files
committed
zsh: make ubuntu compatible
1 parent faf75c5 commit cc976ae

1 file changed

Lines changed: 29 additions & 16 deletions

File tree

zsh/zshrc.zsh

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,36 @@ _source_if_exists "$HOME/.config/secrets/zsh"
2828
# secrets ---
2929

3030
# === Order #1 - Critical Path Setup
31-
32-
# --- Homebrew Setup (ARM/M1+ only)
33-
# Add Homebrew paths first (needed for macOS, no-op on Linux if paths don't exist)
34-
_add_to_path "/opt/homebrew/bin"
35-
_add_to_path "/opt/homebrew/sbin"
36-
3731
# To make Homebrew's completions available
3832
# https://docs.brew.sh/Shell-Completion#configuring-completions-in-zsh
3933
# Note: brew shellenv is slow (~100-300ms), so we manually set the essentials
40-
if [[ -d "/opt/homebrew" ]]; then
41-
export HOMEBREW_PREFIX="/opt/homebrew"
42-
export HOMEBREW_CELLAR="/opt/homebrew/Cellar"
43-
export HOMEBREW_REPOSITORY="/opt/homebrew"
44-
fpath+=("/opt/homebrew/share/zsh/site-functions")
45-
# HOMEBREW_SHELLENV_PREFIX is set for compatibility
46-
export HOMEBREW_SHELLENV_PREFIX="/opt/homebrew"
47-
fi
34+
_setup_homebrew() {
35+
local homebrew_root=0
36+
37+
if [[ $(uname -s) == 'Darwin' ]]; then
38+
homebrew_root='/opt/homebrew'
39+
elif [[ $(uname -s) == 'Linux' ]]; then
40+
homebrew_root='/home/linuxbrew/.linuxbrew'
41+
fi
42+
43+
if [[ -d $homebrew_root ]]; then
44+
# --- Homebrew Setup (ARM/M1+ only)
45+
# Add Homebrew paths first (needed for macOS, no-op on Linux if paths don't exist)
46+
_add_to_path "$homebrew_root/bin"
47+
_add_to_path "$homebrew_root/sbin"
48+
49+
export HOMEBREW_PREFIX="$homebrew_root"
50+
export HOMEBREW_CELLAR="$homebrew_root/Cellar"
51+
export HOMEBREW_REPOSITORY="$homebrew_root"
52+
# HOMEBREW_SHELLENV_PREFIX is set for compatibility
53+
export HOMEBREW_SHELLENV_PREFIX="$homebrew_root"
54+
55+
fpath+=("$homebrew_root/share/zsh/site-functions")
56+
57+
eval "$($homebrew_root/bin/brew shellenv)"
58+
fi
59+
}
60+
_setup_homebrew
4861
# Homebrew Setup ---
4962

5063
# Function to check if zsh completion cache needs regeneration
@@ -85,7 +98,7 @@ _source_if_exists "$Z_CONFIG_DIR/plugins/zsh-autosuggestions/zsh-autosuggestions
8598
# True lazy loading for syntax highlighting - load on first edit
8699
zsh-syntax-highlighting-lazy-load() {
87100
unset -f $0
88-
source "$Z_CONFIG_DIR/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"
101+
_source_if_exists "$Z_CONFIG_DIR/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"
89102
}
90103

91104
autoload -Uz add-zsh-hook
@@ -148,7 +161,7 @@ _source_if_exists "$Z_CONFIG_DIR/secondary.zsh"
148161
if command -v ng &>/dev/null; then
149162
source <(ng completion script)
150163
fi
151-
164+
152165
# Docker completion styles
153166
zstyle ":completion:*:*:docker:*" option-stacking yes
154167
zstyle ":completion:*:*:docker-*:*" option-stacking yes

0 commit comments

Comments
 (0)