fix(zsh): harden shell bootstrap and XDG path setup

This commit is contained in:
Tri Vo Khac committed 2026-07-13 15:55:07 +07:00
1 parent 2cee5ce877
commit fe5c70240e
6 files changed
+46 -26

No files matched your search

+1
View File
@@ -2,3 +2,4 @@
.zsh_history
.zcompcache/
.zsh_sessions/
config/secrets.zsh
+4 -1
View File
@@ -1,5 +1,8 @@
# install zinit
source $ZDOTDIR/zinit.zsh
if ! source "$ZDOTDIR/zinit.zsh"; then
print -u2 "zinit: failed to initialize; skipping plugin configuration"
return 1
fi
zinit light zdharma-continuum/zinit-annex-bin-gem-node
zinit light zdharma-continuum/zinit-annex-binary-symlink
+17 -16
View File
@@ -1,9 +1,11 @@
#!/usr/bin/env zsh
# Define a marker file (choose a location in your cache or temp directory)
MARKER_FILE="${XDG_CACHE_HOME:-$HOME/.cache}/gnu_tools_symlinked"
local brew_prefix="${HOMEBREW_PREFIX:-}"
if [[ -z "$brew_prefix" ]] && command -v brew >/dev/null 2>&1; then
brew_prefix="$(brew --prefix 2>/dev/null)"
fi
if [[ ! -f "$MARKER_FILE" ]]; then
if [[ -n "$brew_prefix" ]]; then
gnu_tools=(
"coreutils"
"findutils"
@@ -14,23 +16,22 @@ if [[ ! -f "$MARKER_FILE" ]]; then
"grep"
)
for tool in $gnu_tools; do
gnubin="/opt/homebrew/opt/$tool/libexec/gnubin"
if [[ -d "$gnubin" ]]; then
for bin in "$gnubin"/*(N); do
ln -sf "$bin" "$XDG_BIN_HOME/$(basename "$bin")"
done
fi
done
# Create the marker file to indicate the script has run
touch "$MARKER_FILE"
if mkdir -p "$XDG_BIN_HOME"; then
for tool in $gnu_tools; do
gnubin="$brew_prefix/opt/$tool/libexec/gnubin"
if [[ -d "$gnubin" ]]; then
for bin in "$gnubin"/*(N); do
target="$XDG_BIN_HOME/${bin:t}"
[[ "$target" -ef "$bin" ]] || ln -sf "$bin" "$target"
done
fi
done
fi
fi
local bin_paths=(
"$XDG_BIN_HOME"
"/opt/homebrew/opt/gnu-getopt/bin"
"${brew_prefix:+$brew_prefix/opt/gnu-getopt/bin}"
)
for bin_path in "${bin_paths[@]}"; do
if [[ -d "$bin_path" ]]; then
+8 -4
View File
@@ -8,9 +8,13 @@ export VISUAL="micro"
export SUDO_EDITOR="micro"
export STARSHIP_CONFIG="$XDG_CONFIG_HOME"/starship/starship.toml
export OPENCODE_EXPERIMENTAL_BACKGROUND_SUBAGENTS=true
export PNPM_HOME="$HOME/.local/share/pnpm"
case ":$PATH:" in
*":$PNPM_HOME/bin:"*) ;;
*) path=("$PNPM_HOME/bin" $path) ;;
esac
typeset -U path
path=(
"$HOME/.opencode/bin"
"$PNPM_HOME/bin"
$path
)
+9 -2
View File
@@ -1,8 +1,15 @@
#!/usr/bin/env zsh
ZINIT_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}/zinit/zinit.git"
[[ ! -d "$ZINIT_HOME" ]] && mkdir -p "$(dirname "$ZINIT_HOME")"
[[ ! -d "$ZINIT_HOME/.git" ]] && git clone --depth 1 https://github.com/zdharma-continuum/zinit.git "$ZINIT_HOME"
if [[ ! -d "$ZINIT_HOME/.git" ]]; then
mkdir -p "$(dirname "$ZINIT_HOME")" || return 1
git clone --depth 1 https://github.com/zdharma-continuum/zinit.git "$ZINIT_HOME" || return 1
fi
if [[ ! -r "$ZINIT_HOME/zinit.zsh" ]]; then
print -u2 "zinit: bootstrap is incomplete at $ZINIT_HOME"
return 1
fi
# not to use aliases: zi or zini
typeset -A ZINIT