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
}
