From 972743df41f6c61b3ec2b683c1ef769c7df85f72 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 26 Nov 2025 18:39:09 +0000 Subject: [PATCH] fix(vanity_setup): Improve script robustness and fix runtime errors This commit addresses three separate issues identified during the execution of the vanity setup script: 1. **Handle existing fonts gracefully**: The `brew_ensure_cask` function is modified to catch the specific error that occurs when a font cask is installed but the font file already exists. Instead of failing, the script now reports the font as already present and continues. 2. **Fix Docker plugin load order**: The `install_zsh_config` function now prepends the `brew shellenv` command to the downloaded `.zshrc` file. This ensures the Homebrew PATH is set *before* Oh My Zsh loads its plugins, resolving the `command not found: docker` error on shell startup. 3. **Automatically update yt-dlp**: The `brew_ensure_formula` function is updated to automatically run `brew upgrade yt-dlp` if the formula is already installed. This keeps the tool up-to-date and prevents download failures (like HTTP 403 errors) caused by an outdated version. --- vanity_setup.sh | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/vanity_setup.sh b/vanity_setup.sh index 118e061..c888e33 100644 --- a/vanity_setup.sh +++ b/vanity_setup.sh @@ -138,7 +138,12 @@ install_homebrew() { brew_ensure_formula() { local formula="$1" if brew list --formula "$formula" >/dev/null 2>&1; then - echo "✔︎ ${formula} ya está instalado. Omitiendo." + if [[ "$formula" == "yt-dlp" ]]; then + echo "➜ yt-dlp ya está instalado. Actualizando a la última versión…" + brew upgrade yt-dlp + else + echo "✔︎ ${formula} ya está instalado. Omitiendo." + fi return fi @@ -154,7 +159,16 @@ brew_ensure_cask() { fi echo "➜ Instalando ${cask}…" - brew install --cask "$cask" + local output + if ! output=$(brew install --cask "$cask" 2>&1); then + if [[ "$output" == *"already a Font at"* ]]; then + echo "✔︎ La fuente de ${cask} ya existe. Omitiendo." + else + echo "$output" >&2 + echo "Error al instalar ${cask}." >&2 + return 1 + fi + fi } install_cli_dependencies() { @@ -257,12 +271,23 @@ install_zsh_config() { mkdir -p "$HOME/.poshthemes" curl -fsSL "$POSH_THEME_URL" -o "$POSH_THEME_PATH" - echo "Descargando .zshrc de Vanity Shell…" - if ! curl -fsSL "$ZSHRC_URL" -o "$HOME/.zshrc"; then + echo "Descargando y configurando .zshrc de Vanity Shell…" + local zshrc_content + if ! zshrc_content=$(curl -fsSL "$ZSHRC_URL"); then echo "No se pudo descargar la configuración de ZSH." >&2 exit 1 fi + local brew_init_line="" + if [ -n "$BREW_BIN" ]; then + # Esta línea se añade al principio para garantizar que el PATH de Homebrew + # se configure ANTES de que Oh My Zsh intente cargar plugins como 'docker'. + brew_init_line="eval \"\$($BREW_BIN shellenv)\"" + fi + + # Combina la inicialización de Homebrew con el contenido descargado + echo -e "${brew_init_line}\n\n${zshrc_content}" > "$HOME/.zshrc" + if command -v pbcopy >/dev/null 2>&1; then echo "source ~/.zshrc" | pbcopy echo "El comando 'source ~/.zshrc' fue copiado al portapapeles."