Created
May 5, 2012 22:36
-
-
Save nerab/2606013 to your computer and use it in GitHub Desktop.
Read MacOS keychain in a shell function
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
function keychain(){ | |
# Keychain access idea from https://github.com/defunkt/gist | |
if [ "$1" ]; then | |
security 2>&1 >/dev/null find-internet-password -gs "$1" | ruby -e 'puts $1 if STDIN.gets =~ /^password: \"(.*)\"$/' | |
else | |
echo No argument given. The following passwords are in your chain: >&2 | |
security dump-keychain | ruby -e 'ARGF.each_line{|line| puts $1 if line =~ /\"srvr\"<blob>=.(.*).$/}' | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment