#!/bin/sh shopt -s nullglob globstar passwordList() { \ prefix=${PASSWORD_STORE_DIR-~/.password-store} password_files=( "$prefix"/**/*.gpg ) password_files=( "${password_files[@]#"$prefix"/}" ) password_files=( "${password_files[@]%.gpg}" ) } getPasswords() { \ choice="$(printf '%s\n' "${password_files[@]}" | dmenu -i -p "Passwords")" if [ ! -z "$choice" ] then pass "$choice" | xclip -selection clipboard notify-send "📋 Password for $choice copied!" sleep 10 printf "" | xclip -selection clipboard fi } getTOTP() { choice="$(printf '%s\n' "${password_files[@]}" | grep "totp" | dmenu -i -p "OTP")" if [ ! -z "$choice" ] then pass otp "$choice" | xclip -selection clipboard notify-send "📋 OTP for $choice copied!" sleep 10 printf "" | xclip -selection clipboard fi } addTOTP() { \ ifinstalled zbarimg || exit name=$(printf "" | dmenu -i -p "What is the account name?") if [ ! -z "$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!" || notify-send "❌ Failed to find QR code!" rm ~/.cache/totp-tmp.png fi } addPassword() { \ name=$(printf "" | dmenu -i -p "What is the account name?") if [ ! -z "$name" ] then 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 '') ;; "Manual password") addPass=$(dmenu -i -P -p "Enter a password") ;; * ) exit esac [ -z $addPass ] && exit echo $addPass | grep "^$" && exit echo $addPass | pass insert "$name" -e notify-send "🔒 Password for $name added!" fi } removePassword() { \ name="$(pass | printf '%s\n' "${password_files[@]}" | dmenu -i -p "Passwords")" [ -z "$name" ] && exit 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 } case "$(printf "View password\\nView TOTP\\nAdd password\\nAdd TOTP\\nRemove password" | dmenu -i -p "Passwords")" in "View password") passwordList && getPasswords ;; "View TOTP") passwordList && getTOTP ;; "Add password") addPassword ;; "Add TOTP") addTOTP ;; "Remove password") passwordList && removePassword ;; esac