xenodium / chatgpt-shell

A multi-llm Emacs shell (ChatGPT, Claude, Gemini, Ollama) + editing integrations
https://lmno.lol/alvaro
GNU General Public License v3.0
862 stars 77 forks source link

Document `auth-source-pass-get` alternative to get secrets from pass #62

Closed meliache closed 1 year ago

meliache commented 1 year ago

Personally, I prefer using

 (auth-source-pass-get 'secret "openai-key")

over

 (nth 0 (process-lines "pass" "show" "openai-key")

auth-source-pass-get is included in the built-in auth-sources library starting from Emacs 26 and autoloaded from Emacs 27.

The already documented auth-source-pick-first-password already works with pass if you add password-store to auth-sources, therefore there's an argument that we already have documentation how to use auth-sources. But auth-source-pass-get works out-of-the-box without customizing the auth-sources variable and its interface is different than using auth-source-pick-first-password with the password-store backend. auth-source-pass-get wants the entire path to the password like pass, e.g. I have something similar to:

 (auth-source-pass-get 'secret "openai.com/keys/emacs")

I found auth-source-pick-first-password sometimes awkward to use with pass because usually you give it :host and it searches the password file basenames (in my example just "emacs") for one matching it and picks the first matching one, which I might get wrong if I have another password ending with "emacs". auth-source-pass-get does no fancy pattern-matching, which I prefer personally.

Still, I only put it into a comment as an alternative next to the process-lines method. Because strictly speaking it's in the heading how to do things without auth-sources, but it's in the auth-sources.el library which still needs to be loaded then. Even though it doesn't use the backends in the auth-sources variable.

xenodium commented 1 year ago

Thanks Michael. Merged it. If keen, invert and comment out the existing way.