voidrice/.local/bin/passwords
cronidea 83558e2b1c
Add option to add OTP to passwords script
Using maim to get a screenshot of the QR code for OTP
2021-08-06 11:13:17 +01:00

79 lines
2.0 KiB
Bash

#!/bin/sh
getPasswords() { \
choice="$(pass | sed -r '1d;s/^├.{3}//;s/^└.{3}//' | dmenu -i -p "Passwords")"
if [ "$choice" != "" ]
then
pass "$choice" | xclip -selection clipboard
notify-send " Password for $choice copied!"
sleep 10
printf "" | xclip -selection clipboard
fi
}
getTOTP() { \
choice="$(pass | grep "totp" | sed -r 's/^├.{3}//;s/^└.{3}//' | dmenu -i -p "OTP")"
if [ "$choice" != "" ]
then
pass otp "$choice" | xclip -selection clipboard
notify-send " OTP for $choice copied!"
sleep 10
printf "" | xclip -selection clipboard
fi
}
addTOTP() { \
name=$(printf "" | dmenu -i -p "What is the account name?")
if [ "$name" != "" ]
then
notify-send "📷 Please screenshot the QR code"
maim -m 10 -d 0.1 -s ~/.cache/totp-tmp.png
zbarimg -q --raw ~/.cache/totp-tmp.png | pass otp insert totp-$name
notify-send " OTP for totp-$name added!"
rm ~/.cache/totp-tmp.png
fi
unset name
}
addPassword() { \
name=$(printf "" | dmenu -i -p "What is the account name?")
if [ "$name" != "" ]
then
case "$(printf "Random password\\nManual password" | dmenu -i -p "Passwords")" in
"Random password") addPass=$(randompass -p $(printf "12\\n32\\n128" | dmenu -i -p "How many characters?")) ;;
"Manual password") addPass=$(dmenu -i -P -p "Enter a password") ;;
esac
echo $addPass | pass insert "$name" -e
notify-send " Password for $name added!"
fi
unset name
unset addPass
}
removePassword() { \
name="$(pass | sed -r '1d;s/^├.{3}//;s/^└.{3}//' | dmenu -i -p "Passwords")"
sure="$(printf "No\\nYes" | dmenu -i -sb "#ac3333" -sf "#111111" -nf "#dddddd" -nb "#111111" -p "Are you sure?")"
if [ $sure = "Yes" ]
then
notify-send " Password for $name removed!"
pass rm "$name" -f
else
notify-send "Canceled"
fi
unset name
}
case "$(printf "Add password\\nView password\\nView TOTP\\nAdd TOTP\\nRemove password" | dmenu -i -p "Passwords")" in
"Add password") addPassword ;;
"View password") getPasswords ;;
"Add TOTP") addTOTP ;;
"View TOTP") getTOTP ;;
"Remove password") removePassword ;;
esac