Created
February 12, 2012 11:39
-
-
Save bradwright/1808116 to your computer and use it in GitHub Desktop.
How to get an OS X KeyChain entry in Emacs (useful for ERC etc.)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun chomp (str) | |
"Chomp leading and tailing whitespace from STR." | |
(while (string-match "\\`\n+\\|^\\s-+\\|\\s-+$\\|\n+\\'" str) | |
(setq str (replace-match "" t t str))) str) | |
(defun get-keychain-password (account-name) | |
"Gets `account` keychain password from OS X Keychain" | |
(chomp | |
(shell-command-to-string | |
(concatenate | |
'string | |
"security 2>&1 >/dev/null find-generic-password -ga " | |
account-name | |
"| sed 's/^password: \\\"\\(.*\\)\\\"/\\1/'")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pretty useful, thank you!