Files
omarchy_setup/modules/icon_manager.sh
google-labs-jules[bot] dbe9bbe4ca 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.
2025-11-19 14:46:57 +00:00

194 lines
7.0 KiB
Bash
Executable File

#!/usr/bin/env bash
# icon_manager.sh (v2)
#
# Un script de gestión para instalar y cambiar entre diferentes temas de iconos
# en un entorno Hyprland/Omarchy. Incluye temas base y personalizaciones.
#
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${SCRIPT_DIR}/common.sh"
# --- Variables Globales ---
AUTOSTART_FILE="$HOME/.config/hypr/autostart.conf"
ICON_DIR_USER="$HOME/.local/share/icons"
# --- Funciones de Utilidad ---
# Función para verificar dependencias
check_deps() {
if ! command_exists git; then
log_error "git no está instalado. Por favor, instálalo para continuar (ej. sudo pacman -S git)."
return 1
fi
return 0
}
# Función para aplicar la configuración de forma persistente
# Argumento 1: Nombre del tema de iconos (ej. 'Tela-nord-dark')
apply_theme() {
local theme_name="$1"
log_info "Aplicando el tema de iconos '$theme_name'..."
mkdir -p "$(dirname "$AUTOSTART_FILE")"
touch "$AUTOSTART_FILE"
# Eliminar cualquier configuración de icon-theme anterior para evitar conflictos
sed -i '/exec-once = gsettings set org.gnome.desktop.interface icon-theme/d' "$AUTOSTART_FILE"
# Añadir el bloque de configuración si no existe
if ! grep -Fq "CONFIGURACIÓN DE TEMA DE ICONOS" "$AUTOSTART_FILE"; then
echo -e "\n# -----------------------------------------------------" >> "$AUTOSTART_FILE"
echo "# CONFIGURACIÓN DE TEMA DE ICONOS" >> "$AUTOSTART_FILE"
echo "# -----------------------------------------------------" >> "$AUTOSTART_FILE"
echo "exec-once = /usr/lib/xdg-desktop-portal-gtk" >> "$AUTOSTART_FILE"
echo "exec-once = sleep 1" >> "$AUTOSTART_FILE"
fi
# Añadir el comando gsettings para el tema seleccionado
echo "exec-once = gsettings set org.gnome.desktop.interface icon-theme '$theme_name'" >> "$AUTOSTART_FILE"
# Aplicar el tema en la sesión actual para un efecto inmediato
gsettings set org.gnome.desktop.interface icon-theme "$theme_name"
log_success "¡Tema configurado! Se aplicó en la sesión actual y se guardó en $AUTOSTART_FILE"
}
# --- Funciones de Instalación de Temas ---
# Función auxiliar para asegurar que el tema base Papirus esté instalado
ensure_papirus_installed() {
local temp_dir="$1"
if [[ ! -d "$ICON_DIR_USER/Papirus-Dark" ]]; then
log_info "El tema base Papirus no está instalado. Instalándolo ahora..."
git clone --depth 1 https://github.com/PapirusDevelopment/papirus-icon-theme.git "$temp_dir/papirus"
"$temp_dir/papirus/install.sh"
else
log_info "El tema base Papirus ya está instalado."
fi
}
# Función para instalar y aplicar el tema Tela Nord (usado como default)
# Argumento 1 (opcional): Directorio temporal a utilizar.
set_default_icon_theme() {
local theme_name="Tela-nord-dark"
local temp_dir_param="${1:-}" # Aceptar directorio temporal como parámetro
log_info "Gestionando el tema de iconos por defecto '$theme_name'..."
if [[ -d "$ICON_DIR_USER/$theme_name" ]]; then
log_info "El tema '$theme_name' ya está instalado."
else
log_info "Instalando el tema '$theme_name'..."
# Si no se pasa un directorio, crear uno propio y limpiarlo.
# Si se pasa, usarlo sin limpiarlo (la función llamadora se encarga).
local temp_dir="${temp_dir_param}"
[[ -z "$temp_dir" ]] && temp_dir=$(mktemp -d)
git clone --depth 1 https://github.com/vinceliuice/Tela-icon-theme.git "$temp_dir/tela"
"$temp_dir/tela/install.sh" -c nord
[[ -z "$temp_dir_param" ]] && rm -rf "$temp_dir"
fi
apply_theme "$theme_name"
}
install_papirus_standard() {
local theme_name="Papirus-Dark"
local temp_dir="$1"
echo "--- Gestionando Papirus Icons (Estándar) ---"
ensure_papirus_installed "$temp_dir"
# Si el usuario quiere el Papirus estándar, restauramos los colores por si acaso
if command_exists papirus-folders; then
papirus-folders --default --theme "$theme_name"
fi
apply_theme "$theme_name"
}
install_candy() {
local theme_name="Candy"
local temp_dir="$1"
echo "--- Gestionando Candy Icons ---"
if [[ -d "$ICON_DIR_USER/$theme_name" ]]; then
log_info "El tema ya está instalado."
else
log_info "Instalando el tema..."
git clone --depth 1 https://github.com/EliverLara/candy-icons.git "$temp_dir/candy"
"$temp_dir/candy/install.sh"
fi
apply_theme "$theme_name"
}
install_papirus_catppuccin() {
local theme_name="Papirus-Dark"
local catppuccin_flavor="mocha"
local temp_dir="$1"
echo "--- Gestionando Papirus Icons con colores Catppuccin ($catppuccin_flavor) ---"
ensure_papirus_installed "$temp_dir"
# 2. Descargar y ejecutar el script de personalización
log_info "Descargando y aplicando el colorizador Catppuccin..."
git clone --depth 1 https://github.com/catppuccin/papirus-folders.git "$temp_dir/papirus-folders-catppuccin"
chmod +x "$temp_dir/papirus-folders-catppuccin/papirus-folders"
# Ejecutar el script para cambiar el color de las carpetas
"$temp_dir/papirus-folders-catppuccin/papirus-folders" -C "catppuccin-${catppuccin_flavor}" --theme "$theme_name"
# 3. Aplicar el tema (el nombre sigue siendo Papirus-Dark, pero los iconos han cambiado)
apply_theme "$theme_name"
}
# --- Función Principal (Menú) ---
run_module_main() {
log_step "Gestor de Temas de Iconos para Hyprland"
if ! check_deps; then
return 1
fi
local temp_dir
temp_dir=$(mktemp -d)
trap 'rm -rf -- "$temp_dir"' EXIT
while true; do
clear
echo -e "${CYAN}==========================================${NC}"
echo -e " ${BOLD}Gestor de Temas de Iconos para Hyprland${NC} "
echo -e "${CYAN}==========================================${NC}"
echo "Selecciona el tema que quieres instalar/activar:"
echo
echo -e " ${GREEN}1)${NC} Tela (variante Nord)"
echo -e " ${GREEN}2)${NC} Papirus (estándar, oscuro)"
echo -e " ${GREEN}3)${NC} Papirus (con colores Catppuccin Mocha)"
echo -e " ${GREEN}4)${NC} Candy Icons"
echo
echo -e " ${YELLOW}q)${NC} Volver al menú principal"
echo
read -p "Tu elección: " choice
# Limpiar el directorio temporal para la nueva operación
rm -rf -- "$temp_dir"/*
case $choice in
1) set_default_icon_theme "$temp_dir" ;;
2) install_papirus_standard "$temp_dir" ;;
3) install_papirus_catppuccin "$temp_dir" ;;
4) install_candy "$temp_dir" ;;
[qQ])
log_info "Volviendo al menú principal."
break
;;
*) log_error "Opción no válida. Inténtalo de nuevo." ;;
esac
if [[ ! "$choice" =~ [qQ] ]]; then
echo
read -p "Presiona Enter para continuar..."
fi
done
return 0
}
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
run_module_main "$@"
fi