Skip to content

Instantly share code, notes, and snippets.

@nerab
Created May 5, 2012 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nerab/2606013 to your computer and use it in GitHub Desktop.
Save nerab/2606013 to your computer and use it in GitHub Desktop.
Read MacOS keychain in a shell function
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