zsh: split functions into zsh-functions, add updater for it
This commit is contained in:
@@ -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
|
||||
}
|
||||
@@ -15,42 +15,8 @@ export ZSHRC_BOOTSTRAP="$ZSH_CONFIG/.bootstrapped"
|
||||
[[ -d "$HOME/AppImages" ]] && path+=("$HOME/AppImages")
|
||||
[[ -d "$HOME/.opencode/bin" ]] && path+=("$HOME/.opencode/bin")
|
||||
|
||||
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
|
||||
}
|
||||
ZSHRC_FUNCTIONS="$ZSH_CONFIG/zsh-functions"
|
||||
source "$ZSHRC_FUNCTIONS"
|
||||
|
||||
# Bootstrap: installs missing CLI tools and oh-my-zsh plugins across distros.
|
||||
if [[ ! -f "$ZSHRC_BOOTSTRAP" || "$(cat "$ZSHRC_BOOTSTRAP" 2>/dev/null)" != "$ZSHRC_BOOTSTRAP_VERSION" || "$BOOTSTRAP" == "true" ]]; then
|
||||
@@ -172,7 +138,7 @@ alias nbstat=$'netbird status --json | jq -r \'.peers.details[]? | [(.hostname /
|
||||
alias open-ports="ss -tulpn | grep LISTEN"
|
||||
alias yeet='yay -Rcs'
|
||||
|
||||
# Auto-update zshrc and starship config on interactive shell start. Disable with ZSHRC_UPDATE_DISABLED=true.
|
||||
# Auto-update zshrc, zsh-functions, and starship config on interactive shell start. Disable with ZSHRC_UPDATE_DISABLED=true.
|
||||
if [[ -o interactive && "$ZSHRC_UPDATE_DISABLED" != "true" ]]; then
|
||||
tmp=/tmp/.zshrc.$$
|
||||
if curl -fsSL --connect-timeout 3 --max-time 8 "$ZSHRC_URL" -o "$tmp" 2>/dev/null \
|
||||
@@ -183,6 +149,16 @@ if [[ -o interactive && "$ZSHRC_UPDATE_DISABLED" != "true" ]]; then
|
||||
fi
|
||||
rm -f "$tmp"
|
||||
|
||||
# zsh-functions
|
||||
ftmp=/tmp/.zsh-functions.$$
|
||||
if curl -fsSL --connect-timeout 3 --max-time 8 "$ZSHRC_GIT/zsh-functions" -o "$ftmp" 2>/dev/null \
|
||||
&& [[ -f "$ftmp" ]] && ! cmp -s "$ftmp" "$ZSHRC_FUNCTIONS" 2>/dev/null; then
|
||||
echo "Updating zsh-functions..."
|
||||
mv "$ftmp" "$ZSHRC_FUNCTIONS"
|
||||
else
|
||||
rm -f "$ftmp"
|
||||
fi
|
||||
|
||||
# starship config
|
||||
if command -v starship >/dev/null; then
|
||||
stmp=$(mktemp)
|
||||
|
||||
Reference in New Issue
Block a user