2022-12-06 08:01:44 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
. $HOME/.bin/_config
|
2024-02-25 14:11:12 +01:00
|
|
|
set -x
|
2022-12-06 08:01:44 +01:00
|
|
|
|
|
|
|
shopt -s nullglob globstar
|
|
|
|
|
|
|
|
prefix=${PASSWORD_STORE_DIR-~/.password-store}
|
|
|
|
password_files=( "$prefix"/**/*.gpg )
|
|
|
|
password_files=( "${password_files[@]#"$prefix"/}" )
|
|
|
|
password_files=( "${password_files[@]%.gpg}" )
|
|
|
|
password=$(printf '%s\n' "${password_files[@]}" | $DMENU_CMD -p Password)
|
|
|
|
|
|
|
|
[[ -n $password ]] || exit
|
|
|
|
|
|
|
|
# read password file
|
|
|
|
password_out=$(pass "$password" 2> /dev/null)
|
|
|
|
|
|
|
|
|
2024-02-25 14:11:12 +01:00
|
|
|
copy_password() {
|
|
|
|
# copy password line
|
|
|
|
printf "%s" "$password_out" | head -1 | xclip -r
|
2022-12-06 08:01:44 +01:00
|
|
|
|
2024-02-25 14:11:12 +01:00
|
|
|
# extract additional information
|
|
|
|
password_info=$(printf "%s" "$password_out" | grep -Ei -m 1 'login|user|email')
|
|
|
|
#url_info=$(printf "%s" "$password_out" | grep -Ei '^url' | awk -F"[ :]*" '{ $1=""; print $0 }' )
|
|
|
|
|
|
|
|
# show desktop notification
|
|
|
|
if [[ -n $password_info ]]; then
|
|
|
|
NOTIFY_CMD "$(printf '%s' "$password_info")"
|
|
|
|
else
|
|
|
|
NOTIFY_CMD "No username provided."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
copy_otp() {
|
|
|
|
password_otp=$(pass otp "$password" 2> /dev/null)
|
|
|
|
printf "%s" "$password_otp" | xclip -r
|
|
|
|
NOTIFY_CMD "$password_otp"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if echo "$password_out" | grep -q otpauth
|
|
|
|
then
|
|
|
|
sel=$(printf 'Copy Password\nCopy OTP' | $DMENU_CMD -p Copy)
|
|
|
|
case $sel in
|
|
|
|
*Password) copy_password; ;;
|
|
|
|
*OTP) copy_otp; ;;
|
|
|
|
esac
|
2022-12-06 08:01:44 +01:00
|
|
|
else
|
2024-02-25 14:11:12 +01:00
|
|
|
copy_password
|
2022-12-06 08:01:44 +01:00
|
|
|
fi
|
2024-02-25 14:11:12 +01:00
|
|
|
|