fix(zsh): harden shell bootstrap and XDG path setup
This commit is contained in:
1 parent
2cee5ce877
commit
fe5c70240e
6 files changed
+40
-20
No files matched your search
@@ -2,3 +2,4 @@
|
|||||||
.zsh_history
|
.zsh_history
|
||||||
.zcompcache/
|
.zcompcache/
|
||||||
.zsh_sessions/
|
.zsh_sessions/
|
||||||
|
config/secrets.zsh
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
# install zinit
|
# 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-bin-gem-node
|
||||||
zinit light zdharma-continuum/zinit-annex-binary-symlink
|
zinit light zdharma-continuum/zinit-annex-binary-symlink
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
#!/usr/bin/env zsh
|
#!/usr/bin/env zsh
|
||||||
|
|
||||||
# Define a marker file (choose a location in your cache or temp directory)
|
local brew_prefix="${HOMEBREW_PREFIX:-}"
|
||||||
MARKER_FILE="${XDG_CACHE_HOME:-$HOME/.cache}/gnu_tools_symlinked"
|
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=(
|
gnu_tools=(
|
||||||
"coreutils"
|
"coreutils"
|
||||||
"findutils"
|
"findutils"
|
||||||
@@ -14,23 +16,22 @@ if [[ ! -f "$MARKER_FILE" ]]; then
|
|||||||
"grep"
|
"grep"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if mkdir -p "$XDG_BIN_HOME"; then
|
||||||
for tool in $gnu_tools; do
|
for tool in $gnu_tools; do
|
||||||
gnubin="/opt/homebrew/opt/$tool/libexec/gnubin"
|
gnubin="$brew_prefix/opt/$tool/libexec/gnubin"
|
||||||
if [[ -d "$gnubin" ]]; then
|
if [[ -d "$gnubin" ]]; then
|
||||||
for bin in "$gnubin"/*(N); do
|
for bin in "$gnubin"/*(N); do
|
||||||
ln -sf "$bin" "$XDG_BIN_HOME/$(basename "$bin")"
|
target="$XDG_BIN_HOME/${bin:t}"
|
||||||
|
[[ "$target" -ef "$bin" ]] || ln -sf "$bin" "$target"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
fi
|
||||||
# Create the marker file to indicate the script has run
|
|
||||||
touch "$MARKER_FILE"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
local bin_paths=(
|
local bin_paths=(
|
||||||
"$XDG_BIN_HOME"
|
"$XDG_BIN_HOME"
|
||||||
"/opt/homebrew/opt/gnu-getopt/bin"
|
"${brew_prefix:+$brew_prefix/opt/gnu-getopt/bin}"
|
||||||
)
|
)
|
||||||
for bin_path in "${bin_paths[@]}"; do
|
for bin_path in "${bin_paths[@]}"; do
|
||||||
if [[ -d "$bin_path" ]]; then
|
if [[ -d "$bin_path" ]]; then
|
||||||
|
|||||||
@@ -8,9 +8,13 @@ export VISUAL="micro"
|
|||||||
export SUDO_EDITOR="micro"
|
export SUDO_EDITOR="micro"
|
||||||
|
|
||||||
export STARSHIP_CONFIG="$XDG_CONFIG_HOME"/starship/starship.toml
|
export STARSHIP_CONFIG="$XDG_CONFIG_HOME"/starship/starship.toml
|
||||||
|
export OPENCODE_EXPERIMENTAL_BACKGROUND_SUBAGENTS=true
|
||||||
|
|
||||||
export PNPM_HOME="$HOME/.local/share/pnpm"
|
export PNPM_HOME="$HOME/.local/share/pnpm"
|
||||||
case ":$PATH:" in
|
|
||||||
*":$PNPM_HOME/bin:"*) ;;
|
typeset -U path
|
||||||
*) path=("$PNPM_HOME/bin" $path) ;;
|
path=(
|
||||||
esac
|
"$HOME/.opencode/bin"
|
||||||
|
"$PNPM_HOME/bin"
|
||||||
|
$path
|
||||||
|
)
|
||||||
@@ -1,8 +1,15 @@
|
|||||||
#!/usr/bin/env zsh
|
#!/usr/bin/env zsh
|
||||||
|
|
||||||
ZINIT_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}/zinit/zinit.git"
|
ZINIT_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}/zinit/zinit.git"
|
||||||
[[ ! -d "$ZINIT_HOME" ]] && mkdir -p "$(dirname "$ZINIT_HOME")"
|
if [[ ! -d "$ZINIT_HOME/.git" ]]; then
|
||||||
[[ ! -d "$ZINIT_HOME/.git" ]] && git clone --depth 1 https://github.com/zdharma-continuum/zinit.git "$ZINIT_HOME"
|
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
|
# not to use aliases: zi or zini
|
||||||
typeset -A ZINIT
|
typeset -A ZINIT
|
||||||
|
|||||||
+7
-3
@@ -1,3 +1,7 @@
|
|||||||
XDG_CONFIG_HOME="${HOME}/.config"
|
export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
|
||||||
XDG_BIN_HOME="${HOME}/.local/bin"
|
export XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
|
||||||
ZDOTDIR="${XDG_CONFIG_HOME}/zsh"
|
export XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
|
||||||
|
export XDG_STATE_HOME="${XDG_STATE_HOME:-$HOME/.local/state}"
|
||||||
|
|
||||||
|
XDG_BIN_HOME="${XDG_BIN_HOME:-$HOME/.local/bin}"
|
||||||
|
ZDOTDIR="$XDG_CONFIG_HOME/zsh"
|
||||||
Reference in new issue
Block a user