Feat: Improve Keyring UX and Icon Manager Flow (#7)

* feat: add dev tools, AI aliases, and improve zshrc documentation

This commit introduces several new features and improvements:

- **Adds Development Tools to `apps.sh`:** The `apps.sh` module now installs essential development tools, including `python`, `pip`, `nodejs`, `npm`, `uv`, and `nvm`.

- **Implements `.zshrc.local` for Private Variables:**
  - A `.zshrc.local.example` file has been added to serve as a template for users to securely store their private environment variables, such as API keys.
  - The main `.zshrc` file now sources `.zshrc.local` if it exists.

- **Adds AI Aliases to `.zshrc`:** A new section has been added to `.zshrc` with example aliases for interacting with command-line AI tools.

- **Improves `.zshrc` Documentation:** The `.zshrc` file has been thoroughly documented with comments in Spanish, explaining the purpose of each section. The title has also been updated and professionalized.

- **Fixes a Regression:** This commit restores the `ytm`, `ytv`, `ytls`, and SSH agent functions in `.zshrc` that were accidentally removed in a previous step.

* feat: improve keyring UX and icon manager flow

This commit introduces two main improvements to the user experience:

1.  **Refactors the Icon Manager for Non-Interactive Installation:**
    - The `icon_manager.sh` module can now be run in a non-interactive mode.
    - The "Install All" process has been updated to use this non-interactive mode, which installs the default icon theme without pausing the script or requiring user input.

2.  **Improves the GNOME Keyring Workflow:**
    - The script no longer errors out if the GNOME Keyring agent is not immediately available after installation.
    - Instead, a clear summary message is now displayed at the end of the "Install All" process, instructing the user to log out and back in, and then run the SSH key synchronization module separately. This provides a much smoother and more intuitive user experience.

---------

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: Marco Gallegos <marco.gallegos@outlook.com>
This commit is contained in:
google-labs-jules[bot]
2025-11-19 08:48:17 -06:00
committed by GitHub
parent e33719682e
commit ae8e3c3c40
14 changed files with 1132 additions and 801 deletions

View File

@@ -1,20 +1,9 @@
#!/usr/bin/env bash
# ===============================================================
# zsh-config.sh - Configuración completa de Zsh
# ===============================================================
#
# Este módulo se encarga de transformar la experiencia de la terminal
# mediante la instalación y configuración de Zsh, Oh My Zsh y Oh My Posh.
# Módulo para configurar Zsh, Oh My Zsh, Oh My Posh y dependencias.
#
# Funciones principales:
# - Instala Zsh y un conjunto de herramientas de terminal útiles.
# - Instala y configura Oh My Posh, incluyendo un tema personalizado.
# - Instala Oh My Zsh y gestiona sus plugins.
# - Descarga y aplica un fichero .zshrc preconfigurado.
# - Cambia el shell por defecto del usuario a Zsh.
#
# ===============================================================
# Asegurarse de que las funciones comunes están cargadas
SCRIPT_DIR_MODULE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SCRIPT_DIR_ROOT="$(cd "${SCRIPT_DIR_MODULE}/.." && pwd)"
if [[ -f "${SCRIPT_DIR_MODULE}/common.sh" ]]; then
@@ -39,35 +28,38 @@ zsh_download_with_timeout() {
install_zsh() {
log_step "Configuración Completa de Zsh"
# Determina el usuario y el directorio home de destino, manejando el caso de `sudo`.
local target_user="${SUDO_USER:-$USER}"
local target_home
local target_home="$HOME"
if [[ -n "${SUDO_USER:-}" ]]; then
target_home="$(getent passwd "$target_user" 2>/dev/null | cut -d: -f6)"
if [[ -z "$target_home" ]]; then
target_home="$(eval echo "~${target_user}")"
fi
fi
target_home="${target_home:-$HOME}"
# --- 1. Instalación de Paquetes ---
log_info "Instalando Zsh y herramientas de terminal..."
# Paquetes:
# - zsh y plugins: El shell y sus complementos básicos.
# - zoxide, fastfetch, yt-dlp: Herramientas que mejoran la productividad
# y están integradas en el .zshrc personalizado.
# --- 1. Instalar paquetes necesarios desde Pacman ---
log_info "Instalando Zsh y herramientas esenciales..."
local pkgs=(
git zsh zsh-completions zsh-syntax-highlighting zsh-autosuggestions
zoxide fastfetch yt-dlp unrar p7zip lsof
git
zsh
zsh-completions
zsh-syntax-highlighting
zsh-autosuggestions
zoxide # Navegación inteligente
fastfetch # Información del sistema
yt-dlp # Descarga de videos/audio
unrar p7zip lsof # Dependencias para funciones en .zshrc
)
if ! sudo pacman -S --noconfirm --needed "${pkgs[@]}"; then
log_warning "Algunos paquetes de Zsh no pudieron instalarse."
fi
for pkg in "${pkgs[@]}"; do
check_and_install_pkg "$pkg"
done
# Instala Oh My Posh, con fallback a AUR y luego al script oficial si es necesario.
# Instalar Oh My Posh con fallback a AUR si es necesario
if ! command_exists oh-my-posh; then
log_info "Instalando Oh My Posh..."
if sudo pacman -S --noconfirm --needed oh-my-posh 2>/dev/null; then
log_success "Oh My Posh instalado desde los repositorios oficiales."
elif aur_install_packages "oh-my-posh-bin"; then
log_success "Oh My Posh instalado desde AUR."
if command_exists pacman && sudo pacman -S --noconfirm --needed oh-my-posh 2>/dev/null; then
log_success "Oh My Posh instalado desde pacman."
else
log_warning "Pacman no pudo instalar oh-my-posh. Intentando con un helper AUR..."
if aur_install_packages "oh-my-posh-bin"; then
@@ -97,7 +89,7 @@ install_zsh() {
log_info "Oh My Posh ya está instalado."
fi
# --- 2. Instalación de Oh My Zsh ---
# --- 2. Instalar Oh My Zsh (si no existe) ---
local target_ohmyzsh_dir="${target_home}/.oh-my-zsh"
if [[ ! -d "$target_ohmyzsh_dir" ]]; then
log_info "Instalando Oh My Zsh..."
@@ -124,48 +116,79 @@ install_zsh() {
log_info "Oh My Zsh ya está instalado."
fi
# --- 3. Gestión de Plugins de Oh My Zsh ---
# Asegura que los plugins de autocompletado y resaltado de sintaxis estén clonados.
# Asegurar plugins personalizados de Oh My Zsh (zsh-autosuggestions, zsh-syntax-highlighting)
local zsh_custom="${target_ohmyzsh_dir}/custom"
local zsh_custom_plugins="${zsh_custom}/plugins"
mkdir -p "$zsh_custom_plugins"
ensure_omz_plugin() {
local name="$1" repo="$2"
local plugin_path="${target_home}/.oh-my-zsh/custom/plugins/${name}"
local name="$1"
local repo="$2"
local plugin_path="${zsh_custom_plugins}/${name}"
if [[ -d "${plugin_path}/.git" ]]; then
log_info "Actualizando el plugin de Oh My Zsh: ${name}..."
log_info "Actualizando plugin ${name}..."
git -C "$plugin_path" pull --ff-only >/dev/null 2>&1 || true
elif [[ ! -d "$plugin_path" ]]; then
log_info "Clonando el plugin de Oh My Zsh: ${name}..."
git clone --depth 1 "$repo" "$plugin_path" >/dev/null 2>&1
elif [[ -d "$plugin_path" ]]; then
log_info "Plugin ${name} ya existe."
else
log_info "Clonando plugin ${name}..."
if git clone --depth 1 "$repo" "$plugin_path" >/dev/null 2>&1; then
log_success "Plugin ${name} instalado."
else
log_warning "No se pudo clonar ${name}. Se usará la versión de los paquetes del sistema."
fi
fi
}
ensure_omz_plugin "zsh-autosuggestions" "https://github.com/zsh-users/zsh-autosuggestions.git"
ensure_omz_plugin "zsh-syntax-highlighting" "https://github.com/zsh-users/zsh-syntax-highlighting.git"
# --- 4. Configuración del .zshrc ---
log_info "Configurando el fichero .zshrc..."
# --- 3. Descargar y configurar el .zshrc personalizado ---
log_info "Actualizando configuración .zshrc..."
local repo_zshrc_path="${SCRIPT_DIR_ROOT}/.zshrc"
local tmp_download="${target_home}/.zshrc.omarchy-tmp"
local source_file=""
if zsh_download_with_timeout "${REPO_BASE}/.zshrc" "$tmp_download" && [[ -s "$tmp_download" ]]; then
source_file="$tmp_download"
# Si falla, usa la copia local que viene con el script.
elif [[ -f "${SCRIPT_DIR_ROOT}/.zshrc" ]]; then
log_warning "No se pudo descargar .zshrc. Se usará la copia local."
source_file="${SCRIPT_DIR_ROOT}/.zshrc"
log_success "Configuración .zshrc descargada desde el repositorio remoto."
else
log_error "No se pudo obtener el fichero .zshrc."; return 1
rm -f "$tmp_download"
if [[ -f "$repo_zshrc_path" ]]; then
log_warning "No se pudo descargar .zshrc. Usando la copia local del repositorio."
source_file="$repo_zshrc_path"
else
log_error "No se pudo obtener la configuración .zshrc (sin red y sin copia local)."
return 1
fi
fi
# Crea una copia de seguridad y reemplaza el .zshrc existente.
backup_file "${target_home}/.zshrc" || { rm -f "$tmp_download"; return 1; }
if ! cp "$source_file" "${target_home}/.zshrc"; then
log_error "No se pudo actualizar el fichero .zshrc."; rm -f "$tmp_download"; return 1
fi
rm -f "$tmp_download"
log_success ".zshrc actualizado correctamente."
# --- 5. Configuración del Tema de Oh My Posh ---
log_info "Configurando el tema de Oh My Posh (Catppuccin Frappe)..."
# Crear copia de seguridad antes de sobrescribir
backup_file "${target_home}/.zshrc" || { rm -f "$tmp_download"; return 1; }
if [[ "$source_file" == "$tmp_download" ]]; then
if mv "$tmp_download" "${target_home}/.zshrc"; then
log_success "Archivo .zshrc actualizado."
else
rm -f "$tmp_download"
log_error "No se pudo mover el archivo .zshrc descargado."
return 1
fi
else
if cp "$source_file" "${target_home}/.zshrc"; then
log_success "Archivo .zshrc actualizado desde la copia local."
else
log_error "No se pudo copiar la configuración .zshrc local."
return 1
fi
fi
# --- 4. Descargar el tema de Oh My Posh ---
log_info "Configurando tema de Oh My Posh (Catppuccin Frappe)..."
local posh_themes_dir="${target_home}/.poshthemes"
local theme_file="$posh_themes_dir/catppuccin_frappe.omp.json"
local posh_theme_local="${SCRIPT_DIR_ROOT}/themes/catppuccin_frappe.omp.json"
mkdir -p "$posh_themes_dir"
if zsh_download_with_timeout "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/catppuccin_frappe.omp.json" "$theme_file"; then
@@ -181,43 +204,59 @@ install_zsh() {
log_error "No se pudo copiar la versión local del tema Catppuccin."
fi
else
log_error "No se pudo obtener el tema de Oh My Posh."
log_error "No se pudo descargar el tema de Oh My Posh y no hay copia local disponible."
# No retornamos error, el .zshrc tiene un fallback
fi
fi
# Genera el fichero de autocompletado para Zsh.
if command_exists oh-my-posh; then
local omp_completion_dir="${target_home}/.local/share/zsh/site-functions"
mkdir -p "$omp_completion_dir"
oh-my-posh completion zsh > "${omp_completion_dir}/_oh-my-posh" 2>/dev/null || true
fi
log_success "Tema de Oh My Posh configurado."
# --- 6. Cambio de Shell por Defecto ---
local current_shell; current_shell="$(getent passwd "$target_user" 2>/dev/null | cut -d: -f7)"
if [[ "$(basename "$current_shell")" != "zsh" ]]; then
log_info "Cambiando el shell por defecto a Zsh para el usuario '$target_user'..."
if ! sudo chsh -s "$(command -v zsh)" "$target_user"; then
log_error "No se pudo cambiar el shell automáticamente."
else
log_success "Shell cambiado a Zsh. El cambio será efectivo en el próximo inicio de sesión."
if oh-my-posh completion zsh > "${omp_completion_dir}/_oh-my-posh" 2>/dev/null; then
log_success "Autocompletado de Oh My Posh actualizado."
fi
fi
# --- 7. Configuración de .bashrc ---
# Añade una línea a .bashrc para que las terminales que se abran con Bash
# ejecuten Zsh automáticamente.
local bashrc_zsh_loader='if [ -t 1 ]; then exec zsh; fi'
if [[ -f "${target_home}/.bashrc" ]] && ! grep -q "exec zsh" "${target_home}/.bashrc"; then
echo -e "\n# Iniciar Zsh automáticamente\n$bashrc_zsh_loader" >> "${target_home}/.bashrc"
# --- 5. Cambiar el shell por defecto a Zsh para el usuario actual ---
local current_shell
current_shell="$(getent passwd "$target_user" 2>/dev/null | cut -d: -f7)"
current_shell="${current_shell:-$SHELL}"
if [[ "$(basename "$current_shell")" != "zsh" ]]; then
log_info "Cambiando el shell por defecto a Zsh..."
local zsh_path
zsh_path="$(command -v zsh)"
if [[ -z "$zsh_path" ]]; then
log_error "No se encontró la ruta de Zsh. Aborta el cambio de shell."
elif sudo -n chsh -s "$zsh_path" "$target_user"; then
log_success "Shell cambiado a Zsh. El cambio será efectivo en el próximo inicio de sesión."
else
log_error "No se pudo cambiar el shell automáticamente. Ejecuta 'sudo chsh -s \"$zsh_path\" $target_user' manualmente."
fi
else
log_info "Zsh ya es el shell por defecto."
fi
# --- 8. Mensaje Final ---
# --- 6. Configurar .bashrc para lanzar Zsh (para sesiones no interactivas) ---
local bashrc_zsh_loader='
# Launch Zsh
if [ -t 1 ]; then
exec zsh
fi'
if [[ -f "${target_home}/.bashrc" ]] && ! grep -q "exec zsh" "${target_home}/.bashrc"; then
log_info "Configurando .bashrc para iniciar Zsh automáticamente..."
echo "$bashrc_zsh_loader" >> "${target_home}/.bashrc"
else
log_info ".bashrc ya está configurado para lanzar Zsh."
fi
# --- 7. Mensaje final ---
echo ""
log_warning ACCIÓN REQUERIDA! Para que los iconos del prompt se vean bien:"
log_info "1. Instala una 'Nerd Font'. La recomendada es Meslo."
log_info " Puedes hacerlo con el comando: oh-my-posh font install meslo"
log_info "2. Configura tu aplicación de terminal para que use la fuente 'MesloLGS NF'."
log_info "3. Cierra y vuelve a abrir la terminal para aplicar todos los cambios."
log_warning IMPORTANTE! Para que los iconos se vean bien, debes configurar tu terminal:"
log_info "1. Abre las Preferencias de tu terminal."
log_info "2. Ve a la sección de Perfil -> Apariencia/Texto."
log_info "3. Cambia la fuente a una 'Nerd Font' (ej: FiraCode Nerd Font, MesloLGS NF)."
log_info "4. Cierra y vuelve a abrir la terminal para ver todos los cambios."
log_warning "Recuerda instalar manualmente una Nerd Font; el script no instala fuentes."
return 0
}