Merge pull request #1 from Venem/patch-1

Make POSIX-compliant and add easy password mode
This commit is contained in:
krisdoodle45 2021-12-10 18:38:46 +01:00 committed by GitHub
commit 2fa2c328cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,34 +1,21 @@
#!/bin/sh #!/bin/sh
shopt -s nullglob globstar
totp_tmp="${XDG_CACHE_HOME:-$HOME/.cache}/totp-tmp.png" totp_tmp="${XDG_CACHE_HOME:-$HOME/.cache}/totp-tmp.png"
passwordList() {
prefix=${PASSWORD_STORE_DIR-~/.password-store}
password_files=("$prefix"/**/*.gpg)
password_files=("${password_files[@]#"$prefix"/}")
password_files=("${password_files[@]%.gpg}")
password_files=$(printf '%s\n' "${password_files[@]}")
}
getPasswords() { getPasswords() {
choice="$(echo "$password_files" | grep -v "totp" | dmenu -i -r -p "Passwords")" choice="$(pass | sed -E "1d;s/(└|├|─|─ )//g" | grep -v "totp" | dmenu -i -p "Passwords")"
[ -z "$choice" ] && exit [ -z "$choice" ] && exit
pass -c "$choice" pass -c "$choice" && notify-send "📋 Password for $choice copied!" || notify-send "⚠️ Something went wrong. Make sure you have initialized pass"
notify-send "📋 Password for $choice copied!" }
}
getTOTP() { getTOTP() {
choice="$(echo "$password_files" | grep "totp" | dmenu -i -r -p "OTP")" choice="$(pass | sed -E "1d;s/(└|├|─|─ )//g" | grep "totp" | dmenu -i -p "OTP")"
[ -z "$choice" ] && exit [ -z "$choice" ] && exit
pass otp -c "$choice" pass otp -c "$choice" && notify-send "⏲️ OTP for $choice copied!" || notify-send "⚠️ Something went wrong. Make sure you have installed pass-totp"
notify-send "📋 OTP for $choice copied!"
} }
addTOTP() { addTOTP() {
@ -40,7 +27,7 @@ addTOTP() {
notify-send "📷 Please screenshot the QR code" notify-send "📷 Please screenshot the QR code"
maim -m 10 -d 0.1 -s "$totp_tmp" maim -m 10 -d 0.1 -s "$totp_tmp"
zbarimg -q --raw "$totp_tmp" | pass otp insert totp-$name && zbarimg -q --raw "$totp_tmp" | pass otp insert totp-"$name" &&
notify-send "🔒 OTP for totp-$name added!" || notify-send "🔒 OTP for totp-$name added!" ||
notify-send "❌ Failed to add QR code!" notify-send "❌ Failed to add QR code!"
rm "$totp_tmp" rm "$totp_tmp"
@ -52,7 +39,18 @@ addPassword() {
[ -z "$name" ] && exit [ -z "$name" ] && exit
case "$(printf "Random password\\nManual password" | dmenu -i -p "Passwords")" in case "$(printf "Random password\\nManual password" | dmenu -i -p "Passwords")" in
"Random password") addPass=$(tr -dc 'A-Za-z0-9!"#$%&'\''()*+,-./:;<=>?@[\]^_`{|}~' </dev/urandom | head -c $(printf "12\\n32\\n128" | dmenu -i -p "How many characters?") ; echo) ;; "Random password")
case "$(printf "Simple\\nComplex" | dmenu -i -p "Passwords")" in
"Simple")
addPass=$(tr -dc 'A-Za-z0-9' </dev/urandom |
head -c "$(printf "12\\n32\\n128" |
dmenu -i -p "How many characters?")" ; echo) ;;
"Complex")
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") ;; "Manual password") addPass=$(dmenu -i -P -p "Enter a password") ;;
* ) exit * ) exit
esac esac
@ -64,7 +62,7 @@ addPassword() {
} }
removePassword() { removePassword() {
name="$(pass | echo "$password_files" | dmenu -i -r -p "Passwords")" name="$(pass | sed -E "1d;s/(└|├|─|─ )//g" | dmenu -i -p "Passwords")"
[ -z "$name" ] && exit [ -z "$name" ] && exit
@ -75,9 +73,9 @@ removePassword() {
} }
case "$(printf "View password\\nView TOTP\\nAdd password\\nAdd TOTP\\nRemove password" | dmenu -i -p "Passwords")" in case "$(printf "View password\\nView TOTP\\nAdd password\\nAdd TOTP\\nRemove password" | dmenu -i -p "Passwords")" in
"View password") passwordList && getPasswords ;; "View password") getPasswords ;;
"View TOTP") passwordList && getTOTP ;; "View TOTP") getTOTP ;;
"Add password") addPassword ;; "Add password") addPassword ;;
"Add TOTP") addTOTP ;; "Add TOTP") addTOTP ;;
"Remove password") passwordList && removePassword ;; "Remove password") removePassword ;;
esac esac