Skip to content

Instantly share code, notes, and snippets.

@bentglasstube
Created May 31, 2012 19:05
Show Gist options
  • Save bentglasstube/2845477 to your computer and use it in GitHub Desktop.
Save bentglasstube/2845477 to your computer and use it in GitHub Desktop.
bash password manager
#!/bin/sh
FILE="$HOME/Dropbox/passwords.gpg"
output=""
search=""
while (( "$#" )); do
if [[ $1 == "-o" ]]; then
output="yes"
else
search="$1"
fi
shift
done
if [ -z $search ]; then
vim $FILE
else
out=$(gpg -q -d $FILE |grep "$search")
if [ $? -ne 0 ]; then
echo "Couldn't find account matching '$search'" >&2
exit 1
fi
lines=$(echo "$out" |wc -l)
if [ $lines -gt 1 ]; then
echo "Choose one:"
echo "$out" |awk '{ print NR ") " $1 ":" $2 }'
read -p "Account? " line
user=$(echo "$out" |awk "NR==$line { print \$2 }")
pass=$(echo "$out" |awk "NR==$line { print \$3 }")
else
user=$(echo "$out" |awk '{ print $2 }')
pass=$(echo "$out" |awk '{ print $3 }')
fi
echo "User: $user";
hash xclip 2>/dev/null
if [ $? -ne 0 ]; then
output="yes"
fi
if [[ -z $output ]]; then
echo -n "$pass" |xclip -selection c
echo "Pass: Copied to clipboard"
else
echo "Pass: $pass"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment