From 36e34165ef08b43c3e93d057c9abe2a9381433f5 Mon Sep 17 00:00:00 2001 From: cronidea <86153674+cronidea@users.noreply.github.com> Date: Sat, 27 Nov 2021 17:38:45 +0000 Subject: [PATCH] Make POSIX-compliant and add easy password mode Unfortunately, arrays aren't included in the POSIX standard so it kept crashing for me. I've tried to debloat my initial solution but I acknowledge that it's not the best way of dealing with listing passwords --- .local/bin/passwords | 46 +++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/.local/bin/passwords b/.local/bin/passwords index 5b93c6fd..4e5967d5 100644 --- a/.local/bin/passwords +++ b/.local/bin/passwords @@ -1,34 +1,21 @@ #!/bin/sh -shopt -s nullglob globstar - 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() { - 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 - pass -c "$choice" - notify-send "📋 Password for $choice copied!" -} + pass -c "$choice" && notify-send "📋 Password for $choice copied!" || notify-send "⚠️ Something went wrong. Make sure you have initialized pass" + } 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 - pass otp -c "$choice" - notify-send "📋 OTP for $choice copied!" + pass otp -c "$choice" && notify-send "⏲️ OTP for $choice copied!" || notify-send "⚠️ Something went wrong. Make sure you have installed pass-totp" } addTOTP() { @@ -40,7 +27,7 @@ addTOTP() { 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 && + 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" @@ -52,7 +39,18 @@ addPassword() { [ -z "$name" ] && exit case "$(printf "Random password\\nManual password" | dmenu -i -p "Passwords")" in - "Random password") addPass=$(tr -dc 'A-Za-z0-9!"#$%&'\''()*+,-./:;<=>?@[\]^_`{|}~' ?@[\]^_`{|}~'