gpg-agent: don't abort nushell startup when tty is unavailable

The nushell integration set $env.GPG_TTY = (tty) unconditionally.
Unlike the bash/zsh/fish variants, which use a plain command
substitution and silently continue with an empty value on failure,
nushell aborts the whole script when an external command used as an
expression value exits non-zero. A missing controlling terminal (e.g.
a login shell invoked non-interactively, such as by WSL's generated
Windows app launchers) made nu exit immediately, breaking every
command run through that login shell.

Wrap the call in try/catch so nushell degrades the same way the other
shell integrations do.
This commit is contained in:
Terje Larsen
2026-10-22 11:53:25 +02:00
committed by Austin Horstman
parent 5d5f3e51a3
commit 2cd3234928
2 changed files with 4 additions and 1 deletions

View File

@@ -44,7 +44,7 @@ let
'';
gpgNushellInitStr = ''
$env.GPG_TTY = (tty)
$env.GPG_TTY = (try { tty } catch { "" })
''
+ optionalString cfg.enableSshSupport ''
${gpgSshSupportStr} | ignore

View File

@@ -19,6 +19,9 @@
assertFileContains \
home-files/.config/nushell/config.nu \
'$env.SSH_AUTH_SOCK = $"(@gnupg@/bin/gpgconf --list-dirs agent-ssh-socket)"'
assertFileContains \
home-files/.config/nushell/config.nu \
'$env.GPG_TTY = (try { tty } catch { "" })'
assertFileContains \
home-files/.zshenv \
'export SSH_AUTH_SOCK="$(@gnupg@/bin/gpgconf --list-dirs agent-ssh-socket)"'