penguin/utils

my env utils

commit 9774602b2d94dab4d6ece45bfcac49868a9a11a2

author斟酌 鵬兄 <tgckpg@gmail.com>
date2026-06-27T11:08:54Z
subjectDo not kill gpg agent every login
commit 9774602b2d94dab4d6ece45bfcac49868a9a11a2
Author: 斟酌 鵬兄 <tgckpg@gmail.com>
Date:   2026-06-27T11:08:54Z

    Do not kill gpg agent every login
---
 bash/sources/15_gpg-agent | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/bash/sources/15_gpg-agent b/bash/sources/15_gpg-agent
index 6ff695a..ac3d530 100644
--- a/bash/sources/15_gpg-agent
+++ b/bash/sources/15_gpg-agent
@@ -1,10 +1,11 @@
 #!/bin/bash
 
-function _rbash_enable_gpg_ssh_support {
-	local _gnupg_home _conf
+function rbash-gpg-agent-enable-ssh {
+	local _gnupg_home _conf _changed
 
 	_gnupg_home="${GNUPGHOME:-$HOME/.gnupg}"
 	_conf="$_gnupg_home/gpg-agent.conf"
+	_changed=
 
 	mkdir -p "$_gnupg_home" || return 1
 	chmod 700 "$_gnupg_home" 2>/dev/null || true
@@ -14,13 +15,16 @@ function _rbash_enable_gpg_ssh_support {
 
 	if ! grep -Eq '^[[:space:]]*enable-ssh-support([[:space:]]|$)' "$_conf"; then
 		printf "\n%s\n" "enable-ssh-support" >> "$_conf"
+		_changed=yes
+	fi
+
+	if [ -n "$_changed" ]; then
+		gpgconf --kill gpg-agent >/dev/null 2>&1 || true
 	fi
 
-	gpgconf --kill gpg-agent >/dev/null 2>&1 || true
 	gpg-connect-agent /bye >/dev/null 2>&1 || true
 }
 
-_rbash_enable_gpg_ssh_support
 _rbash_gpg_enabled=
 
 if command -v gpg-connect-agent >/dev/null 2>&1; then
@@ -31,11 +35,11 @@ if command -v gpg-connect-agent >/dev/null 2>&1; then
 
 	if [ -n "$GPG_TTY" ]; then
 		gpg-connect-agent updatestartuptty /bye >/dev/null 2>&1 || true
-		_rbash_gpg_enabled=yes
 	fi
+
+	_rbash_gpg_enabled=yes
 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"