Compare commits

..
7 Commits
2 changed files with 59 additions and 54 deletions
+36
View File
@@ -0,0 +1,36 @@
use_dev_branch(){
mkdir -p "$ZSH_CONFIG"
echo "dev" > "$ZSH_CONFIG/branch"
export ZSHRC_BRANCH=dev
export ZSHRC_GIT="https://git.jeremymcclure.com/jeremy/scripts/raw/branch/dev/zsh/"
export ZSHRC_URL="$ZSHRC_GIT/zshrc"
export ZSHRC_BOOTSTRAP_URL="$ZSHRC_GIT/zshrc-bootstrap.zsh"
echo "Switched to dev branch. Run 'update_zshrc' to pull latest."
}
use_master_branch(){
rm -f "$ZSH_CONFIG/branch"
export ZSHRC_BRANCH=master
export ZSHRC_GIT="https://git.jeremymcclure.com/jeremy/scripts/raw/branch/master/zsh/"
export ZSHRC_URL="$ZSHRC_GIT/zshrc"
export ZSHRC_BOOTSTRAP_URL="$ZSHRC_GIT/zshrc-bootstrap.zsh"
echo "Switched to master branch. Run 'update_zshrc' to pull latest."
}
update_zshrc(){
local tmp=/tmp/.zshrc.$$
curl -fsSL --connect-timeout 5 --max-time 10 "$ZSHRC_URL" -o "$tmp" 2>/dev/null || return
if zsh -n "$tmp" 2>/dev/null && ! cmp -s "$tmp" "$HOME/.zshrc" 2>/dev/null; then
echo "Updating zshrc..."
mv "$tmp" "$HOME/.zshrc" && echo "Updated. Reloading..." && exec zsh
fi
rm -f "$tmp"
}
fix_btopbg(){
sed -i 's/theme_background = true/theme_background = false/' ~/.config/btop/btop.conf
}
install_opencode(){
curl -fsSL https://opencode.ai/install | bash
}
+23 -54
View File
@@ -2,7 +2,8 @@ export ZSH_CONFIG=$HOME/.config/zsh
export OHMYZSH=$ZSH_CONFIG/oh-my-zsh export OHMYZSH=$ZSH_CONFIG/oh-my-zsh
export OHMYZSH_CUSTOM=$OHMYZSH/custom export OHMYZSH_CUSTOM=$OHMYZSH/custom
export ZSHRC_GIT="https://git.jeremymcclure.com/jeremy/scripts/raw/branch/master/zsh/" export ZSHRC_BRANCH="${ZSHRC_BRANCH:-$(cat "$ZSH_CONFIG/branch" 2>/dev/null || echo master)}"
export ZSHRC_GIT="https://git.jeremymcclure.com/jeremy/scripts/raw/branch/${ZSHRC_BRANCH}/zsh/"
export ZSHRC_URL="$ZSHRC_GIT/zshrc" export ZSHRC_URL="$ZSHRC_GIT/zshrc"
export ZSHRC_BOOTSTRAP_URL="$ZSHRC_GIT/zshrc-bootstrap.zsh" export ZSHRC_BOOTSTRAP_URL="$ZSHRC_GIT/zshrc-bootstrap.zsh"
@@ -14,28 +15,9 @@ export ZSHRC_BOOTSTRAP="$ZSH_CONFIG/.bootstrapped"
[[ -d "$HOME/AppImages" ]] && path+=("$HOME/AppImages") [[ -d "$HOME/AppImages" ]] && path+=("$HOME/AppImages")
[[ -d "$HOME/.opencode/bin" ]] && path+=("$HOME/.opencode/bin") [[ -d "$HOME/.opencode/bin" ]] && path+=("$HOME/.opencode/bin")
update_zshrc(){ [[ -f "$ZSH_CONFIG/zsh-functions.zsh" ]] && source "$ZSH_CONFIG/zsh-functions.zsh"
local tmp=/tmp/.zshrc.$$
curl -fsSL --connect-timeout 5 --max-time 10 "$ZSHRC_URL" -o "$tmp" 2>/dev/null || return
if zsh -n "$tmp" 2>/dev/null && ! cmp -s "$tmp" "$HOME/.zshrc" 2>/dev/null; then
echo "Updating zshrc..."
mv "$tmp" "$HOME/.zshrc" && echo "Updated. Reloading..." && exec zsh
fi
rm -f "$tmp"
}
fix_btopbg(){ # Bootstrap: installs missing CLI tools and oh-my-zsh plugins across distros.
sed -i 's/theme_background = true/theme_background = false/' ~/.config/btop/btop.conf
}
install_opencode(){
curl -fsSL https://opencode.ai/install | bash
}
# Bootstrap: download and run once per bootstrap version. Installs missing CLI
# tools and oh-my-zsh/plugins across distros; prints a banner so the user knows
# what the activity is. Re-runs only when ZSHRC_BOOTSTRAP_VERSION is bumped or
# BOOTSTRAP=true is set.
if [[ ! -f "$ZSHRC_BOOTSTRAP" || "$(cat "$ZSHRC_BOOTSTRAP" 2>/dev/null)" != "$ZSHRC_BOOTSTRAP_VERSION" || "$BOOTSTRAP" == "true" ]]; then if [[ ! -f "$ZSHRC_BOOTSTRAP" || "$(cat "$ZSHRC_BOOTSTRAP" 2>/dev/null)" != "$ZSHRC_BOOTSTRAP_VERSION" || "$BOOTSTRAP" == "true" ]]; then
tmp=/tmp/.zshrc_bootstrap.$$ tmp=/tmp/.zshrc_bootstrap.$$
curl -fsSL --connect-timeout 5 --max-time 10 -o "$tmp" "$ZSHRC_BOOTSTRAP_URL" 2>/dev/null curl -fsSL --connect-timeout 5 --max-time 10 -o "$tmp" "$ZSHRC_BOOTSTRAP_URL" 2>/dev/null
@@ -50,17 +32,12 @@ TMUXCONF="$HOME/.config/tmux"
BYOBUCONF="$HOME/.config/byobu" BYOBUCONF="$HOME/.config/byobu"
TMUXREMOTE="$ZSHRC_GIT/tmux.conf" TMUXREMOTE="$ZSHRC_GIT/tmux.conf"
if [ ! -f "$TMUXCONF/tmux.conf" ] && [ ! -f "$BYOBUCONF/.tmux.conf" ]; then if [ ! -f "$TMUXCONF/tmux.conf" ] && [ ! -f "$BYOBUCONF/.tmux.conf" ]; then
# Create a secure temporary file
TEMP_TMUXCONF=$(mktemp) TEMP_TMUXCONF=$(mktemp)
# Download to temp file.
# The '&&' ensures the 'mv' only runs if curl succeeds (exit code 0).
if curl -fsSL --connect-timeout 5 --max-time 10 -o "$TEMP_TMUXCONF" "$TMUXREMOTE"; then if curl -fsSL --connect-timeout 5 --max-time 10 -o "$TEMP_TMUXCONF" "$TMUXREMOTE"; then
mkdir -p "$TMUXCONF" "$BYOBUCONF" mkdir -p "$TMUXCONF" "$BYOBUCONF"
cp "$TEMP_TMUXCONF" "$TMUXCONF/tmux.conf" cp "$TEMP_TMUXCONF" "$TMUXCONF/tmux.conf"
mv "$TEMP_TMUXCONF" "$BYOBUCONF/.tmux.conf" mv "$TEMP_TMUXCONF" "$BYOBUCONF/.tmux.conf"
else else
# Optional: Clean up temp file if download failed
rm -f "$TEMP_TMUXCONF" rm -f "$TEMP_TMUXCONF"
echo "Error: Failed to download tmux config from $TMUXREMOTE" >&2 echo "Error: Failed to download tmux config from $TMUXREMOTE" >&2
fi fi
@@ -120,10 +97,6 @@ zstyle ':omz:plugins:eza' 'icons' yes
zstyle ':omz:plugins:eza' 'color-scale' all zstyle ':omz:plugins:eza' 'color-scale' all
zstyle ':omz:plugins:eza' 'color-scale-mode' fixed zstyle ':omz:plugins:eza' 'color-scale-mode' fixed
zstyle ':omz:plugins:eza' 'size-prefix' si zstyle ':omz:plugins:eza' 'size-prefix' si
# NOTE: 'hyperlink' is intentionally NOT set here. The oh-my-zsh eza plugin adds
# a bare "--hyperlink" flag which eza (clap) treats as taking the next token as
# its optional value, so `la /` fails with "invalid value '/'". We re-enable
# hyperlinks safely below via the glued `--hyperlink=always` form.
zstyle ':completion:*' menu select zstyle ':completion:*' menu select
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}' zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}'
@@ -132,14 +105,7 @@ zstyle ':completion:*' special-dirs true
source $OHMYZSH/oh-my-zsh.sh source $OHMYZSH/oh-my-zsh.sh
# Re-enable eza hyperlinks, picking the flag form the installed eza supports. # eza hyperlink workaround: oh-my-zsh's bare --hyperlink eats the next arg on newer eza.
# Newer eza: --hyperlink takes an optional value; the oh-my-zsh plugin's bare
# --hyperlink would eat the following path arg (e.g. `la /` -> invalid value '/'),
# so we use the glued --hyperlink=always form.
# Older eza (e.g. Debian's): --hyperlink is a pure boolean and rejects a value,
# so --hyperlink=always errors; the bare --hyperlink is correct and safe there
# (boolean flags don't consume the next token, so the path-eating bug doesn't
# apply).
_hl_flag="--hyperlink" _hl_flag="--hyperlink"
if command -v eza >/dev/null && eza --help 2>&1 | grep -q -- '--hyperlink.*<WHEN>'; then if command -v eza >/dev/null && eza --help 2>&1 | grep -q -- '--hyperlink.*<WHEN>'; then
_hl_flag="--hyperlink=always" _hl_flag="--hyperlink=always"
@@ -149,13 +115,10 @@ for _ea in la ldot lD lDD ll ls lsd lsdl lS lT; do
done done
unset _ea _hl_flag unset _ea _hl_flag
# --- Tool integrations (self-configuring: enabled only when the tool exists) --- # zoxide: frecency-based directory jumping.
# zoxide: frecency-based directory jumping — `z <substring>` / `zi` (fzf picker).
# Replaces nothing; `cd` still works. Auto-installed by the bootstrap.
command -v zoxide >/dev/null && eval "$(zoxide init zsh)" 2>/dev/null command -v zoxide >/dev/null && eval "$(zoxide init zsh)" 2>/dev/null
# bat: colored `cat` and colored man pages. bat/batcat handled by bootstrap. # bat: colored `cat` and colored man pages.
if command -v bat >/dev/null; then if command -v bat >/dev/null; then
alias cat='bat' alias cat='bat'
export BAT_THEME="${BAT_THEME:-Monokai Extended}" export BAT_THEME="${BAT_THEME:-Monokai Extended}"
@@ -163,23 +126,19 @@ if command -v bat >/dev/null; then
export MANROFFOPT='-c' export MANROFFOPT='-c'
fi fi
# delta: prettier git diffs as git's pager (git respects GIT_PAGER). Auto-installed # delta: prettier git diffs as git's pager.
# by the bootstrap. Not aliased to `diff` since delta reads diff input on stdin,
# not two file arguments — GIT_PAGER is the correct integration.
command -v delta >/dev/null && export GIT_PAGER='delta' command -v delta >/dev/null && export GIT_PAGER='delta'
alias c='clear' alias c='clear'
alias q="exit" alias q="exit"
alias usedev='use_dev_branch'
alias usemaster='use_master_branch'
alias nbstat=$'netbird status --json | jq -r \'.peers.details[]? | [(.hostname // .fqdn), .netbirdIp, .status] | @tsv\' | column -t -s $\'\\t\'' alias nbstat=$'netbird status --json | jq -r \'.peers.details[]? | [(.hostname // .fqdn), .netbirdIp, .status] | @tsv\' | column -t -s $\'\\t\''
alias open-ports="ss -tulpn | grep LISTEN" alias open-ports="ss -tulpn | grep LISTEN"
alias yeet='yay -Rcs' alias yeet='yay -Rcs'
# Auto-update self and managed configs: checked every interactive shell start, # Auto-update zshrc, zsh-functions, and starship config on interactive shell start. Disable with ZSHRC_UPDATE_DISABLED=true.
# silently skipped if the server is unreachable. Keeps zshrc + starship.toml in if [[ -o interactive && "$ZSHRC_UPDATE_DISABLED" != "true" ]]; then
# sync across machines (reproducible/self-configuring); only reloads the shell
# when the zshrc itself changes (starship applies its config live per render).
if [[ -o interactive ]]; then
# zshrc (reload shell if changed)
tmp=/tmp/.zshrc.$$ tmp=/tmp/.zshrc.$$
if curl -fsSL --connect-timeout 3 --max-time 8 "$ZSHRC_URL" -o "$tmp" 2>/dev/null \ if curl -fsSL --connect-timeout 3 --max-time 8 "$ZSHRC_URL" -o "$tmp" 2>/dev/null \
&& [[ -f "$tmp" ]] && zsh -n "$tmp" 2>/dev/null \ && [[ -f "$tmp" ]] && zsh -n "$tmp" 2>/dev/null \
@@ -189,7 +148,17 @@ if [[ -o interactive ]]; then
fi fi
rm -f "$tmp" rm -f "$tmp"
# starship prompt config (overwrite if changed; applied live on next render) # zsh-functions
ftmp=/tmp/.zsh-functions.$$
if curl -fsSL --connect-timeout 3 --max-time 8 "$ZSHRC_GIT/zsh-functions.zsh" -o "$ftmp" 2>/dev/null \
&& [[ -f "$ftmp" ]] && ! cmp -s "$ftmp" "$ZSH_CONFIG/zsh-functions.zsh" 2>/dev/null; then
echo "Updating zsh-functions..."
mv "$ftmp" "$ZSH_CONFIG/zsh-functions.zsh"
else
rm -f "$ftmp"
fi
# starship config
if command -v starship >/dev/null; then if command -v starship >/dev/null; then
stmp=$(mktemp) stmp=$(mktemp)
if curl -fsSL --connect-timeout 3 --max-time 8 "$ZSHRC_GIT/starship.toml" -o "$stmp" 2>/dev/null \ if curl -fsSL --connect-timeout 3 --max-time 8 "$ZSHRC_GIT/starship.toml" -o "$stmp" 2>/dev/null \