From 8e370fec399704387db8a62111f2e4fdea0c4ff1 Mon Sep 17 00:00:00 2001 From: Marco Gallegos Date: Sat, 15 Nov 2025 12:10:28 -0600 Subject: [PATCH] Enhance setup scripts: update Oh My Posh theme reference, add Epson driver installation from AUR, and improve cleanup on exit in main script. --- .zshrc | 18 ++-- modules/printer.sh | 15 +++- modules/zsh-config.sh | 192 +++++++++++++++++++++--------------------- omarchy-setup.sh | 5 ++ 4 files changed, 124 insertions(+), 106 deletions(-) diff --git a/.zshrc b/.zshrc index 0b1ae3b..3692c8e 100644 --- a/.zshrc +++ b/.zshrc @@ -43,15 +43,15 @@ zstyle ':completion:*' menu select source "${ZSH_CUSTOM:-$ZSH/custom}/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" # --- Oh My Posh -------------------------------------------------------------- -# Asegúrate de que Oh My Posh esté instalado y el tema 'catppuccin.omp.json' +# Asegúrate de que Oh My Posh esté instalado y el tema 'catppuccin_frappe.omp.json' # esté en ~/.poshthemes/ if command -v oh-my-posh >/dev/null 2>&1; then - if [ -f ~/.poshthemes/catppuccin.omp.json ]; then - eval "$(oh-my-posh init zsh --config ~/.poshthemes/catppuccin.omp.json)" + if [ -f ~/.poshthemes/catppuccin_frappe.omp.json ]; then + eval "$(oh-my-posh init zsh --config ~/.poshthemes/catppuccin_frappe.omp.json)" else - # Fallback si el tema Catppuccin no se encuentra + # Fallback si el tema Catppuccin Frappe no se encuentra eval "$(oh-my-posh init zsh)" - echo "Advertencia: Tema Catppuccin para Oh My Posh no encontrado en ~/.poshthemes/. Usando el tema por defecto." + echo "Advertencia: Tema Catppuccin Frappe para Oh My Posh no encontrado en ~/.poshthemes/. Usando el tema por defecto." fi fi @@ -354,10 +354,10 @@ alias ssh-github='ssh -T git@github.com' # Test GitHub connection if command -v zoxide >/dev/null 2>&1; then eval "$(zoxide init zsh)" - # Alias para compatibilidad con el comportamiento tradicional - alias cd='z' - alias cdi='zi' # Interactive mode - alias zz='z -' # Ir al directorio anterior + # zoxide se integra con 'cd'. Para usarlo de forma explícita o interactiva, + # puedes usar 'z' y 'zi'. + alias zz='z -' # Ir al directorio anterior + alias zi='zi' # Modo interactivo else echo "Advertencia: zoxide no está instalado. Instálalo para usar 'z', 'zi', 'zz'." fi diff --git a/modules/printer.sh b/modules/printer.sh index 70f4570..ed7c3fa 100755 --- a/modules/printer.sh +++ b/modules/printer.sh @@ -21,6 +21,20 @@ install_printer() { return 1 } + # Instalar drivers específicos desde AUR (para Epson) + log_info "Buscando drivers de Epson en AUR..." + local AUR_DRIVERS=("epson-inkjet-printer-escpr" "epson-inkjet-printer-escpr2") + local AUR_HELPER + AUR_HELPER=$(ensure_aur_helper) + + if [[ -n "$AUR_HELPER" ]]; then + log_info "Instalando drivers de Epson con ${AUR_HELPER}..." + "$AUR_HELPER" -S --noconfirm --needed "${AUR_DRIVERS[@]}" || log_warning "No se pudieron instalar todos los drivers de Epson desde AUR." + else + log_error "No se encontró un ayudante de AUR (yay, paru). No se pueden instalar los drivers de Epson." + # No retornamos error, el resto de la configuración puede continuar + fi + # Habilitar y iniciar servicios log_info "Habilitando servicios de impresora..." sudo systemctl enable cups.service @@ -45,4 +59,3 @@ install_printer() { if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then install_printer "$@" fi - diff --git a/modules/zsh-config.sh b/modules/zsh-config.sh index 0627acd..272a796 100755 --- a/modules/zsh-config.sh +++ b/modules/zsh-config.sh @@ -1,107 +1,107 @@ #!/usr/bin/env bash -# =============================================================== -# zsh-config.sh - Configuración de Zsh y shell -# =============================================================== +# +# Módulo para configurar Zsh, Oh My Zsh, Oh My Posh y dependencias. +# -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -source "${SCRIPT_DIR}/common.sh" - -# Usar REPO_BASE si está definido, sino usar el valor por defecto -REPO_BASE="${REPO_BASE:-https://raw.githubusercontent.com/marcogll/omarchy_setup/main}" - -configure_bashrc_to_launch_zsh() { - local bashrc_file="$HOME/.bashrc" - local block_marker="# OMARCHY: AUTO-LAUNCH ZSH" - - if [[ -f "$bashrc_file" ]] && grep -qF "$block_marker" "$bashrc_file"; then - log_success ".bashrc ya está configurado para lanzar Zsh." - return 0 - fi - - log_info "Configurando .bashrc para lanzar Zsh automáticamente..." - - # Crear copia de seguridad - if [[ -f "$bashrc_file" ]]; then - cp "$bashrc_file" "${bashrc_file}.bak_$(date +%F_%T)" - log_info "Copia de seguridad de .bashrc creada en ${bashrc_file}.bak_..." - fi - - # Añadir el bloque de código a .bashrc - cat >> "$bashrc_file" << 'EOF' - -# OMARCHY: AUTO-LAUNCH ZSH -# Lanzar Zsh automáticamente si no estamos ya en Zsh -if [ -t 1 ] && [ -z "$ZSH_VERSION" ] && command -v zsh &>/dev/null; then - # Inicializar Homebrew si existe antes de cambiar de shell - if [ -f "/home/linuxbrew/.linuxbrew/bin/brew" ]; then - eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" - fi - exec zsh +# Asegurarse de que las funciones comunes están cargadas +SCRIPT_DIR_MODULE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +if [[ -f "${SCRIPT_DIR_MODULE}/common.sh" ]]; then + source "${SCRIPT_DIR_MODULE}/common.sh" +else + echo "Error: common.sh no encontrado." + exit 1 fi -EOF - log_success ".bashrc modificado para iniciar Zsh." -} install_zsh() { - log_step "Configuración de Zsh" - - # Instalar Zsh y plugins - log_info "Instalando Zsh y complementos..." - # El spinner se inicia desde el script principal, aquí solo ejecutamos el comando - sudo pacman -S --noconfirm --needed \ - zsh zsh-completions zsh-syntax-highlighting zsh-autosuggestions || { - log_error "Error al instalar Zsh" - return 1 - } - - # No es necesario un spinner aquí, es muy rápido - # Descargar configuración personalizada - log_info "Descargando configuración de Zsh desde GitHub..." - if curl -fsSL "${REPO_BASE}/.zshrc" -o ~/.zshrc; then - # Añadir configuración de Homebrew si está instalado - if [[ -x "/home/linuxbrew/.linuxbrew/bin/brew" ]]; then - log_info "Añadiendo configuración de Homebrew a .zshrc..." - echo '' >> ~/.zshrc - echo '# Homebrew' >> ~/.zshrc - echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> ~/.zshrc + log_step "Configuración Completa de Zsh" + + # --- 1. Instalar paquetes necesarios desde Pacman --- + log_info "Instalando Zsh y herramientas esenciales..." + local pkgs=( + zsh + zsh-completions + zsh-syntax-highlighting + zsh-autosuggestions + oh-my-posh # Para el prompt + zoxide # Navegación inteligente + fastfetch # Información del sistema + yt-dlp # Descarga de videos/audio + nerd-fonts # Paquete de fuentes con iconos + unrar p7zip lsof # Dependencias para funciones en .zshrc + ) + for pkg in "${pkgs[@]}"; do + check_and_install_pkg "$pkg" + done + + # --- 2. Instalar Oh My Zsh (si no existe) --- + if [[ ! -d "$HOME/.oh-my-zsh" ]]; 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 + sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended --keep-zshrc + if [[ $? -ne 0 ]]; then + log_error "Falló la instalación de Oh My Zsh." + return 1 fi - log_success "Configuración de Zsh descargada" else - log_warning "No se pudo descargar .zshrc desde GitHub" - log_info "Creando configuración básica de Zsh..." - cat > ~/.zshrc << 'EOF' -# Zsh básico -autoload -U compinit -compinit - -# Plugins -source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh -source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh - -# Historial -HISTFILE=~/.zsh_history -HISTSIZE=10000 -SAVEHIST=10000 -setopt SHARE_HISTORY -setopt HIST_IGNORE_DUPS - -# Aliases útiles -alias ll='ls -lah' -alias la='ls -A' -alias l='ls -CF' -alias ..='cd ..' -alias ...='cd ../..' -EOF + log_info "Oh My Zsh ya está instalado." fi + + # --- 3. Descargar y configurar el .zshrc personalizado --- + log_info "Descargando configuración .zshrc desde el repositorio..." + if curl -fsSL "${REPO_BASE}/.zshrc" -o "$HOME/.zshrc.omarchy-tmp"; then + mv "$HOME/.zshrc.omarchy-tmp" "$HOME/.zshrc" + log_success "Archivo .zshrc actualizado." + else + log_error "No se pudo descargar el archivo .zshrc." + return 1 + fi + + # --- 4. Descargar el tema de Oh My Posh --- + log_info "Configurando tema de Oh My Posh (Catppuccin Frappe)..." + local posh_themes_dir="$HOME/.poshthemes" + local theme_file="$posh_themes_dir/catppuccin_frappe.omp.json" + mkdir -p "$posh_themes_dir" - # Modificar .bashrc para que lance zsh - configure_bashrc_to_launch_zsh + if curl -fsSL "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/catppuccin_frappe.omp.json" -o "$theme_file"; then + log_success "Tema Catppuccin Frappe descargado en $theme_file" + else + log_error "No se pudo descargar el tema de Oh My Posh." + # No retornamos error, el .zshrc tiene un fallback + fi + + # --- 5. Cambiar el shell por defecto a Zsh para el usuario actual --- + if [[ "$(basename "$SHELL")" != "zsh" ]]; then + log_info "Cambiando el shell por defecto a Zsh..." + # chsh requiere la contraseña del usuario + if chsh -s "$(which zsh)"; 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. Por favor, ejecute 'chsh -s $(which zsh)' manualmente." + fi + else + log_info "Zsh ya es el shell por defecto." + fi + + # --- 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 "$HOME/.bashrc" ]] && ! grep -q "exec zsh" "$HOME/.bashrc"; then + log_info "Configurando .bashrc para iniciar Zsh automáticamente..." + echo "$bashrc_zsh_loader" >> "$HOME/.bashrc" + else + log_info ".bashrc ya está configurado para lanzar Zsh." + fi + + # --- 7. Mensaje final --- + echo "" + 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_success "Configuración de Zsh completada" return 0 -} - -# Ejecutar si se llama directamente -if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then - install_zsh "$@" -fi +} \ No newline at end of file diff --git a/omarchy-setup.sh b/omarchy-setup.sh index c232820..763e490 100755 --- a/omarchy-setup.sh +++ b/omarchy-setup.sh @@ -181,6 +181,11 @@ install_all() { # Función principal main() { + # Limpieza al salir: detener el spinner y restaurar el cursor + trap 'stop_spinner 1 "Script interrumpido." >/dev/null 2>&1; exit 1' INT TERM + # Limpieza final al salir normalmente + trap 'tput cnorm' EXIT + # Verificar que estamos en Arch Linux if [[ ! -f /etc/arch-release ]]; then log_error "Este script está diseñado para Arch Linux"