feat: Enhance Zsh configuration and setup scripts with improved plugin management and GNOME Keyring integration

This commit is contained in:
Marco Gallegos
2025-11-18 13:15:06 -06:00
parent ee8ff3c5ef
commit de2e8071ab
7 changed files with 257 additions and 37 deletions

View File

@@ -31,6 +31,7 @@ run_module_main() {
local PACMAN_BASE=(
git curl wget base-devel unzip htop fastfetch btop
vim nano tmux xdg-utils xdg-user-dirs stow
gnome-keyring libsecret seahorse openssh rsync
)
local PACMAN_MULTIMEDIA=(
vlc vlc-plugins-all libdvdcss audacity inkscape
@@ -145,6 +146,71 @@ run_module_main() {
# Configurar servicios
log_info "Configurando servicios..."
log_info "Configurando GNOME Keyring como agente de credenciales..."
mkdir -p "${HOME}/.config/environment.d"
cat <<'EOF' > "${HOME}/.config/environment.d/10-gnome-keyring.conf"
SSH_AUTH_SOCK=/run/user/$UID/keyring/ssh
EOF
if systemctl --user enable --now gnome-keyring-daemon.socket gnome-keyring-daemon.service >/dev/null 2>&1; then
log_success "GNOME Keyring listo para gestionar contraseñas y claves SSH."
else
log_warning "No se pudo habilitar gnome-keyring-daemon en systemd de usuario. Verifica que tu sesión use systemd (--user)."
fi
if command_exists gnome-keyring-daemon; then
local keyring_eval
keyring_eval="$(gnome-keyring-daemon --start --components=secrets,ssh 2>/dev/null)" || keyring_eval=""
if [[ -n "$keyring_eval" ]]; then
eval "$keyring_eval"
fi
fi
local keyring_socket="/run/user/$UID/keyring/ssh"
if [[ -S "$keyring_socket" ]]; then
export SSH_AUTH_SOCK="$keyring_socket"
fi
log_info "Vuelve a iniciar sesión para que las variables de entorno del keyring se apliquen."
if command_exists ssh-add; then
local ssh_dir="${HOME}/.ssh"
if [[ -d "$ssh_dir" ]]; then
mapfile -t ssh_private_keys < <(find "$ssh_dir" -maxdepth 1 -type f -name "id_*" ! -name "*.pub" ! -name "*-cert.pub" 2>/dev/null)
if [[ ${#ssh_private_keys[@]} -gt 0 ]]; then
log_info "Agregando claves SSH detectadas al keyring (se solicitará la passphrase si aplica)..."
for key_path in "${ssh_private_keys[@]}"; do
if [[ ! -r "$key_path" ]]; then
log_warning "No se puede leer la clave $(basename "$key_path"); revísala manualmente."
continue
fi
if ssh-keygen -y -f "$key_path" >/dev/null 2>&1; then
log_info "Registrando clave $(basename "$key_path")..."
local spinner_was_active=0
if [[ -n "${SPINNER_PID:-}" ]]; then
spinner_was_active=1
fi
if declare -F pause_spinner >/dev/null; then
pause_spinner
fi
if SSH_AUTH_SOCK="$SSH_AUTH_SOCK" ssh-add "$key_path"; then
log_success "Clave $(basename "$key_path") añadida al keyring."
else
log_warning "No se pudo añadir la clave $(basename "$key_path")."
fi
if (( spinner_was_active )) && declare -F resume_spinner >/dev/null; then
resume_spinner
fi
else
log_warning "La clave $(basename "$key_path") parece inválida. Se omite."
fi
done
else
log_info "No se encontraron claves privadas SSH en ${ssh_dir}."
fi
else
log_info "No se detectó el directorio ~/.ssh; omitiendo carga de claves."
fi
else
log_warning "ssh-add no está disponible; no se pueden registrar claves en el keyring."
fi
# Habilitar keyd si está instalado
if command_exists keyd; then
log_info "Habilitando servicio keyd..."

View File

@@ -14,19 +14,29 @@ NC='\033[0m' # No Color
BOLD='\033[1m'
# Funciones de logging
_maybe_clear_spinner() {
if declare -F spinner_clear_line >/dev/null; then
spinner_clear_line
fi
}
log_info() {
_maybe_clear_spinner
echo -e "${BLUE}${NC} ${BOLD}$1${NC}"
}
log_success() {
_maybe_clear_spinner
echo -e "${GREEN}${NC} ${GREEN}$1${NC}"
}
log_warning() {
_maybe_clear_spinner
echo -e "${YELLOW}${NC} ${YELLOW}$1${NC}"
}
log_error() {
_maybe_clear_spinner
echo -e "${RED}${NC} ${RED}$1${NC}"
}

0
modules/disk-format.sh Normal file → Executable file
View File

View File

@@ -29,6 +29,7 @@ install_zsh() {
# --- 1. Instalar paquetes necesarios desde Pacman ---
log_info "Instalando Zsh y herramientas esenciales..."
local pkgs=(
git
zsh
zsh-completions
zsh-syntax-highlighting
@@ -79,6 +80,34 @@ install_zsh() {
else
log_info "Oh My Zsh ya está instalado."
fi
# 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"
local repo="$2"
local plugin_path="${zsh_custom_plugins}/${name}"
if [[ -d "${plugin_path}/.git" ]]; then
log_info "Actualizando plugin ${name}..."
git -C "$plugin_path" pull --ff-only >/dev/null 2>&1 || true
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"
# --- 3. Descargar y configurar el .zshrc personalizado ---
log_info "Actualizando configuración .zshrc..."
@@ -145,6 +174,14 @@ install_zsh() {
fi
fi
if command_exists oh-my-posh; then
local omp_completion_dir="${target_home}/.local/share/zsh/site-functions"
mkdir -p "$omp_completion_dir"
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
# --- 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)"