From f0e9471acbce661d6ddf560e0b26b64de887c7f5 Mon Sep 17 00:00:00 2001 From: Marco Gallegos Date: Tue, 18 Nov 2025 16:45:21 -0600 Subject: [PATCH 1/2] refactor --- modules/apps.sh | 43 +++++++++++++++++++++++++++++++++++ modules/common.sh | 16 ++++++++++--- modules/zsh-config.sh | 53 +++++++++++++++++++++++++++++++++++-------- 3 files changed, 100 insertions(+), 12 deletions(-) diff --git a/modules/apps.sh b/modules/apps.sh index a9a6263..88b473f 100755 --- a/modules/apps.sh +++ b/modules/apps.sh @@ -6,11 +6,53 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "${SCRIPT_DIR}/common.sh" +ensure_homebrew_env() { + local brew_bin="$1" + if [[ ! -x "$brew_bin" ]]; then + return 1 + fi + + # Eval shellenv so el resto del módulo pueda usar brew sin reiniciar la shell. + eval "$("$brew_bin" shellenv)" || return 1 + + local shell_snippet='eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' + local -a appended=() + local -a rc_targets=("${HOME}/.profile") + + if [[ -n "${SHELL:-}" && "$(basename "${SHELL}")" == "zsh" ]]; then + rc_targets+=("${HOME}/.zprofile") + fi + + for rc_file in "${rc_targets[@]}"; do + if [[ -f "$rc_file" ]] && grep -Fq "$shell_snippet" "$rc_file"; then + continue + fi + { + echo "" + echo "# Configuración añadida por Omarchy Setup para inicializar Homebrew" + echo "$shell_snippet" + } >> "$rc_file" + appended+=("$rc_file") + done + + if [[ ${#appended[@]} -gt 0 ]]; then + log_info "Se añadió la inicialización de Homebrew a: ${appended[*]}." + fi + + return 0 +} + install_homebrew() { log_step "Instalación de Homebrew (Linuxbrew)" + local brew_path="/home/linuxbrew/.linuxbrew/bin/brew" if command_exists brew; then + brew_path="$(command -v brew)" + fi + + if command_exists brew || [[ -x "$brew_path" ]]; then log_success "Homebrew ya está instalado." + ensure_homebrew_env "${brew_path}" || true return 0 fi @@ -18,6 +60,7 @@ install_homebrew() { # Instalar de forma no interactiva if NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"; then log_success "Homebrew instalado correctamente." + ensure_homebrew_env "${brew_path}" || log_warning "Homebrew se instaló pero no se pudo configurar la shell automáticamente." else log_error "Falló la instalación de Homebrew." return 1 diff --git a/modules/common.sh b/modules/common.sh index dd1e828..e1a0a4b 100755 --- a/modules/common.sh +++ b/modules/common.sh @@ -125,16 +125,26 @@ aur_install_packages() { return 1 fi - local -a base_flags=(--noconfirm --needed --noeditmenu --nodiffmenu --nocleanmenu) + local -a base_flags=(--noconfirm --needed) AUR_HELPER_CMD="$helper" local status=0 case "$helper" in yay) - "$helper" -S "${base_flags[@]}" --answerdiff None --answerclean All --answeredit None --mflags "--noconfirm" --cleanafter "${packages[@]}" + "$helper" -S "${base_flags[@]}" \ + --answerdiff None \ + --answerclean All \ + --answeredit None \ + --mflags "--noconfirm" \ + --cleanafter \ + "${packages[@]}" status=$? ;; paru) - "$helper" -S "${base_flags[@]}" --skipreview --cleanafter --mflags "--noconfirm" "${packages[@]}" + "$helper" -S "${base_flags[@]}" \ + --skipreview \ + --cleanafter \ + --mflags "--noconfirm" \ + "${packages[@]}" status=$? ;; *) diff --git a/modules/zsh-config.sh b/modules/zsh-config.sh index 0f787ee..a134cc6 100755 --- a/modules/zsh-config.sh +++ b/modules/zsh-config.sh @@ -13,6 +13,18 @@ else exit 1 fi +# Opciones comunes para curl con timeout moderado y reintentos breves. +ZSH_CURL_TIMEOUT_OPTS=(--fail --location --silent --show-error --connect-timeout 10 --max-time 60 --retry 2 --retry-delay 2) + +zsh_download_with_timeout() { + local url="$1" + local dest="$2" + if curl "${ZSH_CURL_TIMEOUT_OPTS[@]}" -o "$dest" "$url"; then + return 0 + fi + return 1 +} + install_zsh() { log_step "Configuración Completa de Zsh" @@ -55,10 +67,20 @@ install_zsh() { else log_warning "No se pudo instalar Oh My Posh mediante pacman ni AUR." log_info "Descargando instalador oficial de Oh My Posh..." - if curl -fsSL https://ohmyposh.dev/install.sh | sudo bash -s -- -d /usr/local/bin; then - log_success "Oh My Posh instalado usando el script oficial." + local omp_installer + omp_installer="$(mktemp)" + if [[ -n "$omp_installer" ]] && zsh_download_with_timeout "https://ohmyposh.dev/install.sh" "$omp_installer"; then + if sudo bash "$omp_installer" -d /usr/local/bin; then + log_success "Oh My Posh instalado usando el script oficial." + else + log_error "Falló la instalación de Oh My Posh usando el script oficial." + rm -f "$omp_installer" + return 1 + fi + rm -f "$omp_installer" else - log_error "Fallo la instalación de Oh My Posh usando el script oficial." + rm -f "${omp_installer:-}" + log_error "No se pudo descargar el instalador oficial de Oh My Posh." return 1 fi fi @@ -71,12 +93,25 @@ install_zsh() { local target_ohmyzsh_dir="${target_home}/.oh-my-zsh" if [[ ! -d "$target_ohmyzsh_dir" ]]; then log_info "Instalando Oh My Zsh..." - # Usar RUNZSH=no para evitar que inicie un nuevo shell y CHSH=no para no cambiar el shell aún - if ! env HOME="$target_home" RUNZSH=no CHSH=no \ - sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended --keep-zshrc; then - log_error "Falló la instalación de Oh My Zsh." + local omz_installer + omz_installer="$(mktemp)" + if [[ -z "$omz_installer" ]]; then + log_error "No se pudo crear un archivo temporal para el instalador de Oh My Zsh." return 1 fi + if zsh_download_with_timeout "https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh" "$omz_installer"; then + # Usar RUNZSH=no para evitar que inicie un nuevo shell y CHSH=no para no cambiar el shell aún + if ! env HOME="$target_home" RUNZSH=no CHSH=no sh "$omz_installer" --unattended --keep-zshrc; then + rm -f "$omz_installer" + log_error "Falló la instalación de Oh My Zsh." + return 1 + fi + else + rm -f "$omz_installer" + log_error "No se pudo descargar el instalador de Oh My Zsh." + return 1 + fi + rm -f "$omz_installer" else log_info "Oh My Zsh ya está instalado." fi @@ -115,7 +150,7 @@ install_zsh() { local tmp_download="${target_home}/.zshrc.omarchy-tmp" local source_file="" - if curl -fsSL "${REPO_BASE}/.zshrc" -o "$tmp_download" && [[ -s "$tmp_download" ]]; then + if zsh_download_with_timeout "${REPO_BASE}/.zshrc" "$tmp_download" && [[ -s "$tmp_download" ]]; then source_file="$tmp_download" log_success "Configuración .zshrc descargada desde el repositorio remoto." else @@ -156,7 +191,7 @@ install_zsh() { local posh_theme_local="${SCRIPT_DIR_ROOT}/themes/catppuccin_frappe.omp.json" mkdir -p "$posh_themes_dir" - if curl -fsSL "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/catppuccin_frappe.omp.json" -o "$theme_file"; then + if zsh_download_with_timeout "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/catppuccin_frappe.omp.json" "$theme_file"; then chmod 644 "$theme_file" 2>/dev/null || true log_success "Tema Catppuccin Frappe descargado en $theme_file" else From a2fbb1166b8f2c0bbbfdd8a503ef4c51b37b123b Mon Sep 17 00:00:00 2001 From: Marco Gallegos Date: Tue, 18 Nov 2025 17:10:44 -0600 Subject: [PATCH 2/2] docs: update and improve Readme.md in Spanish (#2) Restore the comprehensive Spanish version of the `Readme.md` and add a new section with instructions for installing the Meslo font, which is required for the `oh-my-posh` theme to render correctly. The new section is located in the "Troubleshooting" area and provides the necessary command (`oh-my-posh font install meslo`) to ensure a correct setup. The rest of the document has been reviewed to ensure it is complete and accurately reflects the script's functionality. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> --- Readme.md | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/Readme.md b/Readme.md index b60fbe4..9e9627e 100644 --- a/Readme.md +++ b/Readme.md @@ -558,20 +558,28 @@ ztstatus ### Oh My Posh no se muestra correctamente +Para que el tema de Oh My Posh se visualice correctamente, es **esencial** tener instalada una "Nerd Font". Estas fuentes incluyen los íconos y símbolos especiales que usa el prompt. + +El script **no** instala fuentes automáticamente, pero puedes hacerlo fácilmente con el siguiente comando: + ```bash -# Verificar instalación +# Instalar la fuente recomendada (Meslo LGM Nerd Font) +oh-my-posh font install meslo +``` + +Después de instalar la fuente, **debes configurar tu emulador de terminal** para que la use. Este paso es crucial y varía según la terminal que utilices (por ejemplo, en GNOME Terminal, Konsole, Alacritty, etc., deberás ir a sus preferencias y seleccionar "MesloLGM Nerd Font"). + +**Verificaciones adicionales:** + +```bash +# Verificar que oh-my-posh está instalado which oh-my-posh -oh-my-posh version # Verificar que el tema existe ls ~/.poshthemes/catppuccin_frappe.omp.json -# Verificar que tienes una Nerd Font instalada -# (El script NO instala fuentes automáticamente) -fc-list | grep -i nerd - -# Si no tienes Nerd Font, instala una: -# - Nerd Fonts: https://www.nerdfonts.com/ +# Listar fuentes para confirmar que Meslo está instalada +fc-list | grep -i "meslo" ``` ### El shell no cambió a Zsh