l5tools/bwui

46 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
# Prompt for master password
PASS=$(yad --title "Master Password" --width=400 --entry --hide-text)
RC=$?
if [[ $RC -eq 1 ]]; then
exit 0
fi
# Unlock the session
export BW_SESSION=$(bw unlock $PASS --raw)
if [[ ${#BW_SESSION} -eq 0 ]]; then
yad --title "Error" --text="Invalid master password." --button="Close"
exit 1
fi
# Prompt for a search
SEARCH=$(yad --form --title "Search Bitwarden" --width=400 --entry)
RC=$?
if [[ $RC -eq 1 ]]; then
exit 0
fi
# Display the results
SID=$(bw list items --search "$SEARCH" | \
jq '.[] | {id, name, username: .login.username, url: .login.url}' | \
jq '.id,.name,.username,.url' | \
yad --title "Bitwarden Entries" --list --width=600 --height=600 \
--column="ID" --column="Name" --column="Username" --column="URL" \
--hide-column=1 | cut -d '|' -f 1 | tr -d '"')
if [[ ${#SID} -eq 0 ]]; then
exit 0
fi
# Fetch the password for a selected entry
PW=$(bw get password "$SID")
yad --title "BW" --text="Password ready." --button="Copy:2" --button="Close:1"
RC=$?
if [[ $RC -eq 2 ]]; then
echo $PW | wl-copy
yad --title "BW" --button="Close:1"
fi
wl-copy --clear