]> git.sev.monster Git - dotfiles.git/commitdiff
fix gpg agent setup and pretty printing
authorsev <git@sev.monster>
Sun, 20 Mar 2022 03:48:01 +0000 (22:48 -0500)
committersev <git@sev.monster>
Fri, 5 Apr 2024 21:27:40 +0000 (16:27 -0500)
only setup if not forwarded, pointless otherwise
minimize complexity with pretty printing info, don't /echo if forwarded

base/.zprofile

index 648cf5522f469b32a70b567f5fe31c4254e00df0..0d8a1a71f2188cbca93ff4e00310736d731a784f 100644 (file)
@@ -290,33 +290,39 @@ if [[ -v commands[gpg-connect-agent] && ( ! -v _sev_setup_gpgagent ||
     if {$p} {
         print -nP '%F{blue}>>>%f GPG: '
         if [[ -v _sev_setup_gpg_forward ]] {
-            a=agent
-            print -nP '%F{yellow}Forwarded%f '
-        } else { a=Agent }
-        print -nP '%F{green}'
+            print -nP '%F{yellow}Forwarded agent '
+        } else {
+            print -nP '%F{green}Agent '
+        }
     }
     gpg-connect-agent /bye >/dev/null 2>&1
     if [[ $? -ne 0 ]] {
-        $p && print -P '%F{red}$a communication error'
+        $p && print -P '%F{red}communication error'
     } else {
-        if [[ ${+GPG_TTY} -eq 0 && -o interactive ]]
-            export GPG_TTY=$(tty)
-        if [[ ( -v DISPLAY || -v WAYLAND_DISPLAY ) &&
-              ${PINENTRY_USER_DATA/USE_TTY=0} == $PINENTRY_USER_DATA ]]
-            export PINENTRY_USER_DATA=USE_TTY=$((
-              ${+DISPLAY} + ${+WAYLAND_DISPLAY} == 0))
-        # XXX: don't know if gpg-agent supports comments after directives
-        # XXX: path could have #
-        sed -Ei 's#^([[:space:]]*pinentry-program[[:space:]]).*$#\1'${commands[pinentry]:-/dev/null}'#' \
-          ${GNUPGHOME:-~/.gnupg}/gpg-agent.conf
-        # XXX: could probably check for changes before doing this to save perf
-        gpg-connect-agent RELOADAGENT UPDATESTARTUPTTY /bye >/dev/null 2>&1
-        $p && gpg-connect-agent /subst /serverpid \
-                "/echo $a pid \${get serverpid} on $GPG_TTY" /bye
+        if [[ ! -v _sev_setup_gpg_forward ]] {
+            if [[ ${+GPG_TTY} -eq 0 && -o interactive ]]
+                export GPG_TTY=$(tty)
+            if [[ ( -v DISPLAY || -v WAYLAND_DISPLAY ) &&
+                  ${PINENTRY_USER_DATA/USE_TTY=0} == $PINENTRY_USER_DATA ]]
+                export PINENTRY_USER_DATA=USE_TTY=$((
+                  ${+DISPLAY} + ${+WAYLAND_DISPLAY} == 0))
+            # XXX: don't know if gpg-agent supports comments after directives
+            # XXX: path could have #
+            sed -Ei 's#^([[:space:]]*pinentry-program[[:space:]]).*$#\1'${commands[pinentry]:-/dev/null}'#' \
+              ${GNUPGHOME:-~/.gnupg}/gpg-agent.conf
+            # XXX: could check for changes before doing this to save perf
+            gpg-connect-agent RELOADAGENT UPDATESTARTUPTTY /bye >/dev/null 2>&1
+            if {$p} {
+                gpg-connect-agent /subst /serverpid \
+                  "/echo pid \${get serverpid} on $GPG_TTY" /bye 2>/dev/null
+                print -nP '%f'
+            }
+        } elif {$p} {
+            print -P '%f'
+        }
         export _sev_setup_gpgagent=
     }
-    $p && print -nP '%f'
-    unset p a
+    unset p
 }
 
 ### ssh agent
This page took 0.042006 seconds and 4 git commands to generate.