voidrice/.local/bin/passwords

82 lines
2.7 KiB
Bash

#!/bin/sh
totp_tmp="${XDG_CACHE_HOME:-$HOME/.cache}/totp-tmp.png"
getPasswords() {
choice="$(find "${PASSWORD_STORE_DIR--~/.password-store}" -type f | sed "s|${PASSWORD_STORE_DIR-~/.password-store}/|| ; s/.gpg$// ; /.gpg-id/d" | sort | grep -v "totp" | dmenu -i -p "Passwords")"
[ -z "$choice" ] && exit
pass -c "$choice" && notify-send "📋 Password for $choice copied!" || notify-send "⚠️ Something went wrong. Make sure you have initialized pass"
}
getTOTP() {
choice="$(find "${PASSWORD_STORE_DIR--~/.password-store}" -type f | sed "s|${PASSWORD_STORE_DIR-~/.password-store}/|| ; s/.gpg$// ; /.gpg-id/d" | sort | grep "totp" | dmenu -i -p "OTP")"
[ -z "$choice" ] && exit
pass otp -c "$choice" && notify-send "⏲️ OTP for $choice copied!" || notify-send "⚠️ Something went wrong. Make sure you have installed pass-totp"
}
addTOTP() {
ifinstalled zbarimg || exit
name=$(printf "" | dmenu -i -p "What is the account name?")
[ -z "$name" ] && exit
notify-send "📷 Please screenshot the QR code"
maim -m 10 -d 0.1 -s "$totp_tmp"
zbarimg -q --raw "$totp_tmp" | pass otp insert totp-"$name" &&
notify-send "🔒 OTP for totp-$name added!" ||
notify-send "❌ Failed to add QR code!"
rm "$totp_tmp"
}
addPassword() {
name=$(printf "" | dmenu -i -p "What is the account name?")
[ -z "$name" ] && exit
case "$(printf "Random password\\nManual password" | dmenu -i -p "Passwords")" in
"Random password")
case "$(printf "Complex\\nSimple" | dmenu -i -p "Passwords")" in
"Complex")
addPass=$(tr -dc 'A-Za-z0-9!"#$%&'\''()*+,-./:;<=>?@[\]^_`{|}~' </dev/urandom | \
head -c "$(printf "12\\n32\\n128" |
dmenu -i -p "How many characters?")" ; echo) ;;
"Simple")
addPass=$(tr -dc 'A-Za-z0-9' </dev/urandom |
head -c "$(printf "12\\n32\\n128" |
dmenu -i -p "How many characters?")" ; echo) ;;
* ) exit ;;
esac ;;
"Manual password") addPass=$(dmenu -i -P -p "Enter a password") ;;
* ) exit
esac
[ -z "$addPass" ] && exit
echo "$addPass" | pass insert "$name" -e
notify-send "🔒 Password for $name added!"
}
removePassword() {
name="$(find "${PASSWORD_STORE_DIR--~/.password-store}" -type f | sed "s|${PASSWORD_STORE_DIR-~/.password-store}/|| ; s/.gpg$// ; /.gpg-id/d" | sort | dmenu -i -p "Passwords")"
[ -z "$name" ] && exit
prompt "Are you sure?" &&
pass rm "$name" -f &&
notify-send "❎ Password for $name removed!" ||
notify-send "Canceled"
}
case "$(printf "View password\\nView TOTP\\nAdd password\\nAdd TOTP\\nRemove password" | dmenu -i -p "Passwords")" in
"View password") getPasswords ;;
"View TOTP") getTOTP ;;
"Add password") addPassword ;;
"Add TOTP") addTOTP ;;
"Remove password") removePassword ;;
esac