Looking at how Magit handles password prompts, it uses Emacs's process handling system with specific filters to detect and intercept password requests. Here's how it works:
How Magit Catches Password Prompts
Magit uses magit-process-password-prompt-regexps to detect password prompts. The key components are:
-
Process Filter: Magit sets up a process filter (magit-process-filter) that watches the output
-
Password Detection: It matches output against patterns like:
;; Default patterns in magit-process.el
'("^\\(Enter \\)?[Pp]assphrase\\( for \\(RSA \\)?key '.*'\\)?: ?$"
"^\\(Enter \\)?[Pp]assword\\( for '?\\(https?://\\)?\\(?99:.*\\)'?\\)?: ?$"
"Please enter the passphrase for the ssh key"
"Please enter the passphrase to unlock the OpenPGP secret key"
"^.*'s password: ?$"
"^Token: $"
"^Yubikey for .*: ?$"
"^Enter PIN for .*: ?$")
-
The Hook: When detected, it calls magit-process-password-auth-source or prompts via minibuffer
Why Your Mixin Breaks This
The issue is likely that:
ssh-add might be outputting to stderr instead of stdout
- The prompt format from
ssh-add might not match the regexps
- Your wrapper might be running ssh-add in a subprocess that doesn't inherit the process filter
Solutions
Solution 1: Make Your Wrapper Compatible
Ensure your wrapper script properly forwards stderr to stdout and uses unbuffered output:
#!/bin/bash
# Your wrapper script
exec 2>&1 # Redirect stderr to stdout
stty -echo 2>/dev/null || true # Prevent echo issues
# Run ssh-add with proper output handling
SSH_ASKPASS_REQUIRE=force ssh-add "$@" 2>&1
# Then run the original ssh-keygen
exec /usr/bin/ssh-keygen "$@"
Solution 2: Add ssh-add Pattern to Magit
Add the ssh-add prompt pattern to Magit's configuration:
(with-eval-after-load 'magit-process
(add-to-list 'magit-process-password-prompt-regexps
"^Enter passphrase for .*: ?$"))
Solution 3: Use SSH_ASKPASS Instead
Configure ssh-add to use a GUI prompt or Emacs-based askpass:
;; Create an askpass helper that works with Magit
(setenv "SSH_ASKPASS_REQUIRE" "force")
(setenv "SSH_ASKPASS"
(expand-file-name
"~/.emacs.d/emacs-ssh-askpass.sh"))
With emacs-ssh-askpass.sh:
#!/bin/bash
emacsclient -e "(read-passwd \"$@\")" | sed 's/^"\(.*\)"$/\1/'
Solution 4: Use Emacs's Built-in SSH Agent Support
Instead of a wrapper, use Emacs's keychain support:
(use-package keychain-environment
:config
(keychain-refresh-environment))
Solution 5: Debug Your Current Setup
To see what's happening, enable Magit process debugging:
(setq magit-process-echo-command-as-string t)
(setq magit-git-debug t)
;; Add a custom filter to see all output
(advice-add 'magit-process-filter :before
(lambda (proc string)
(message "Process output: %s" string)))
The most robust solution is probably Solution 1 combined with Solution 2 - make sure your wrapper properly handles I/O and add the ssh-add prompt pattern to Magit's regexp list.