39 lines
1.4 KiB
Bash
Executable File
39 lines
1.4 KiB
Bash
Executable File
#!/bin/bash
|
|
export BW_SESSION = your token here
|
|
|
|
[[ $# -eq 0 ]] && query=$(echo -e "\n" | dmenu -p "What to search:") || query=$@
|
|
# the query is passed through parameters, if not it's asked through a text-box
|
|
|
|
usersdmenu=""
|
|
userssplit=""
|
|
passwords=""
|
|
|
|
json=$(bw list items --search $query)
|
|
length=$(echo $json | jq -r 'length') #how many accounts found for that site
|
|
for row in $(echo "${json}" | jq -r '.[] | @base64'); do
|
|
_jq() { #this function is used to loop through the multiple results
|
|
echo ${row} | base64 --decode | jq -r ${1}
|
|
}
|
|
|
|
# echo $(_jq '.login.username')
|
|
user="$(echo $(_jq '.login.username'))"
|
|
usersdmenu="$usersdmenu$user\n" #array used for the choosing phase in dmenu
|
|
userssplit="$userssplit$user," #array used for extracting the password from the json
|
|
|
|
password="$(_jq '.login.password')"
|
|
passwords="$passwords$password,"
|
|
done
|
|
IFS=","
|
|
read -r -a usersarray <<< "$userssplit"
|
|
read -r -a passwordsarray <<< "$passwords"
|
|
unset IFS
|
|
|
|
[[ $length -eq 1 ]] && chosen=${usersarray[0]} || chosen="$(echo -e $usersdmenu | dmenu)"
|
|
# if there is only one result just copy the password of that account to the clipboard
|
|
|
|
for index in "${!usersarray[@]}"
|
|
do
|
|
# echo "$index ${sarray[index]}"
|
|
[[ ${usersarray[index]} = $chosen ]] && echo "${passwordsarray[index]}" | xclip -selection c && notify-send Found "copied to clipboard password of user:${usersarray[index]}, site:$query"
|
|
done
|