fix(vanity_setup): Resolve Docker PATH and font configuration errors

This commit addresses two critical errors discovered during script execution:

1.  **Fix Docker PATH loading issue**: The previous method of initializing the Homebrew environment was not consistently effective. This has been replaced with a more robust method that explicitly prepends the Homebrew bin and sbin directories to the `PATH` at the very beginning of the `.zshrc` file. This ensures that all Homebrew-installed commands, such as `docker`, are available before Oh My Zsh and its plugins are loaded.

2.  **Fix `unbound variable` error in font script**: The `configure_terminal_font` function was rewritten to invoke `osascript` using a series of `-e` arguments instead of a heredoc. This change prevents the shell from misinterpreting the AppleScript code, resolving the `font_name?: unbound variable` error.
This commit is contained in:
google-labs-jules[bot]
2025-11-26 19:23:50 +00:00
parent 56bba92e29
commit bc694db36d

View File

@@ -138,7 +138,12 @@ install_homebrew() {
brew_ensure_formula() {
local formula="$1"
if brew list --formula "$formula" >/dev/null 2>&1; then
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() {
@@ -200,16 +214,15 @@ configure_terminal_font() {
font_size=14
echo "Configurando Terminal para usar la fuente $font_name"
/usr/bin/osascript <<OSA >/dev/null 2>&1
tell application "Terminal"
try
set font name of default settings to "$font_name"
set font size of default settings to "$font_size"
set font name of startup settings to "$font_name"
set font size of startup settings to "$font_size"
end try
end tell
OSA
osascript >/dev/null 2>&1 \
-e "tell application \"Terminal\"" \
-e " try" \
-e " set font name of default settings to \"${font_name}\"" \
-e " set font size of default settings to ${font_size}" \
-e " set font name of startup settings to \"${font_name}\"" \
-e " set font size of startup settings to ${font_size}" \
-e " end try" \
-e "end tell"
}
install_oh_my_zsh() {
@@ -257,12 +270,25 @@ 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_path_line=""
if [ -n "$BREW_BIN" ]; then
local brew_prefix
brew_prefix=$("$BREW_BIN" --prefix)
# 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_path_line="export PATH=\"${brew_prefix}/bin:${brew_prefix}/sbin:\$PATH\""
fi
# Combina la inicialización de Homebrew con el contenido descargado
echo -e "${brew_path_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."
@@ -333,6 +359,14 @@ install_docker_stack() {
portainer/portainer-ce:latest >/dev/null
}
update_packages() {
echo "Actualizando la lista de paquetes de Homebrew…"
install_homebrew
echo "Actualizando todos los paquetes de Homebrew instalados…"
brew upgrade
echo "Todos los paquetes han sido actualizados."
}
ensure_xcode_clt() {
if xcode-select -p >/dev/null 2>&1; then
return
@@ -415,11 +449,12 @@ main_menu() {
echo " A) Instalar TODO (recomendado)"
echo " C) Instalar solo configuración ZSH"
echo " D) Instalar Docker + Portainer + Lazydocker"
echo " P) Actualizar paquetes Homebrew"
echo " U) Actualizar componentes instalados"
echo " Q) Salir"
echo ""
local choice=""
if read_menu_choice "Opción [A/C/D/U/Q]: "; then
if read_menu_choice "Opción [A/C/D/P/U/Q]: "; then
choice="$REPLY"
else
echo "No se detecta una entrada interactiva; se seleccionará la opción 'A' por defecto."
@@ -440,6 +475,9 @@ main_menu() {
install_homebrew
install_docker_stack
;;
P|p)
update_packages
;;
U|u)
echo "Actualizando la instalación existente…"
install_homebrew