From 28563efe0cc27569a89b5ca3277cf635b435914e Mon Sep 17 00:00:00 2001 From: Marco Raber Date: Sun, 23 Aug 2020 01:00:30 +0200 Subject: [PATCH] Added script --- README.md | 2 +- bwSearch | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100755 bwSearch diff --git a/README.md b/README.md index 76391e8..0c27371 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Bash script that copies passwords into the clipboard from the bitwarden-cli ## Installation -Download the file, make it executable, run, enjoy +Download the file, make it executable (`chmod +x /path/to/bwSearch`), run, enjoy ## Usage `bwSearch name_of_the_website` diff --git a/bwSearch b/bwSearch new file mode 100755 index 0000000..cacebfe --- /dev/null +++ b/bwSearch @@ -0,0 +1,33 @@ +#!/bin/bash +export BW_SESSION="I3J/FBkJVUwu+Aa2vRBuHZYxZ66kGKJ4TQa2km3JhxI9WfSLRMl2Ew0BxlNMrGMMGxfqH56MYEc5pW+xszGZww==" +[[ $# -eq 0 ]] && query=$(zenity --entry --text="Sito" --entry-text="git..") || query=$@ +usersdmenu="" +userssplit="" +passwords="" +json=$(bw list items --search $query) +length=$(bw list items --search $query | jq -r 'length') +for row in $(echo "${json}" | jq -r '.[] | @base64'); do + _jq() { + echo ${row} | base64 --decode | jq -r ${1} + } + + # echo $(_jq '.login.username') + user="$(echo $(_jq '.login.username'))" + usersdmenu="$usersdmenu$user\n" + userssplit="$userssplit$user," + password="$(_jq '.login.password')" + passwords="$passwords$password," +done +IFS="," +read -r -a usersarray <<< "$userssplit" +read -r -a passwordsarray <<< "$passwords" +unset IFS + +[[ $length -eq 1 ]] && scelta=${usersarray[0]} || scelta="$(echo -e $usersdmenu | dmenu)" + + +for index in "${!usersarray[@]}" +do + # echo "$index ${sarray[index]}" + [[ ${usersarray[index]} = $scelta ]] && echo "${passwordsarray[index]}" | xclip -selection c && notify-send Found "copied to clipboard password of user:${usersarray[index]}, site:$query" +done