#!/bin/bash function _rbash_enable_gpg_ssh_support { local _gnupg_home _conf _gnupg_home="${GNUPGHOME:-$HOME/.gnupg}" _conf="$_gnupg_home/gpg-agent.conf" mkdir -p "$_gnupg_home" || return 1 chmod 700 "$_gnupg_home" 2>/dev/null || true touch "$_conf" || return 1 chmod 600 "$_conf" 2>/dev/null || true if ! grep -Eq '^[[:space:]]*enable-ssh-support([[:space:]]|$)' "$_conf"; then printf "\n%s\n" "enable-ssh-support" >> "$_conf" fi gpgconf --kill gpg-agent >/dev/null 2>&1 || true gpg-connect-agent /bye >/dev/null 2>&1 || true } _rbash_enable_gpg_ssh_support if command -v gpg-connect-agent >/dev/null 2>&1; then export GPG_TTY GPG_TTY="$(tty 2>/dev/null || true)" gpg-connect-agent /bye >/dev/null 2>&1 || true if [ -n "$GPG_TTY" ]; then gpg-connect-agent updatestartuptty /bye >/dev/null 2>&1 || true fi fi # Optional: use gpg-agent as ssh-agent only when configured. if command -v gpgconf >/dev/null 2>&1 && [ -f "${GNUPGHOME:-$HOME/.gnupg}/gpg-agent.conf" ] && grep -Eq '^[[:space:]]*enable-ssh-support([[:space:]]|$)' "${GNUPGHOME:-$HOME/.gnupg}/gpg-agent.conf" then _rbash_gpg_ssh_sock="$(gpgconf --list-dirs agent-ssh-socket 2>/dev/null || true)" if [ -n "$_rbash_gpg_ssh_sock" ]; then export SSH_AUTH_SOCK="$_rbash_gpg_ssh_sock" fi unset _rbash_gpg_ssh_sock fi