From 15e75bb089540747fd66ae2229f5c828f28d8945 Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Fri, 18 Nov 2022 18:08:05 +0100 Subject: bin/passmenu: rename to secretmenu and make it work with bitwarden --- bin/passmenu | 60 +---------------------------------------- bin/secretmenu | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 59 deletions(-) mode change 100755 => 120000 bin/passmenu create mode 100755 bin/secretmenu (limited to 'bin') diff --git a/bin/passmenu b/bin/passmenu deleted file mode 100755 index e81a29a..0000000 --- a/bin/passmenu +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/bash - -set -eo pipefail -[ -n "$DEBUG" ] && set -x - -trap '{ notify-send -a passmenu -i "$(iconez -n form-textbox-passworrd)" -c error "passmenu: failed :(" "pipefail"; exit 1; }' ERR - -# check requirements -for tool in bemenu fd fzf; do - if ! command -v "$tool" >/dev/null; then - printf "%s: %s not installed but required\n" "$(basename "$0")" "$tool" >&2 - exit 1 - fi -done - -typeit= -if [ "$1" = "--type" ]; then - typeit=1 - shift -fi - -if [ "$1" = "-t" ]; then - _dmenu() { - fzf - } -else - _dmenu() { - MENU_PROMPT="󰌆 pass" menu - } -fi - -prefix=${PASSWORD_STORE_DIR-~/.password-store} -prefix=$(readlink -f -- "${prefix}") -password_files=$( - fd -e gpg . "${prefix}" | sed -e "s#${prefix}/##" -e 's#\.gpg$##' -) - -password=$(printf '%s\n' "${password_files[@]}" | _dmenu "$@") -[ -n "$password" ] || exit 1 - -err=$(pass show "$password" 2>&1 | - awk 'NR==1 {system("wl-copy -o -n " $0);hit+=1} /^Username:/ {system("wl-copy -n -p " $2);hit+=1} END{if(hit==0) print("no password found")}') - -# shellcheck disable=SC2181 -if [ "$?" -ne 0 ] || [ -n "$err" ]; then - notify-send \ - -a passmenu \ - -i /usr/share/icons/mdi/scalable/form-textbox-password.svg \ - -c error \ - 'passmenu: failed :(' \ - "${err}" - exit 1 -fi - -notify-send \ - -a passmenu \ - -i /usr/share/icons/mdi/scalable/form-textbox-password.svg \ - 'passmenu: password copied' \ - 'will be removed after next paste' diff --git a/bin/passmenu b/bin/passmenu new file mode 120000 index 0000000..e7f48fd --- /dev/null +++ b/bin/passmenu @@ -0,0 +1 @@ +secretmenu \ No newline at end of file diff --git a/bin/secretmenu b/bin/secretmenu new file mode 100755 index 0000000..42399cc --- /dev/null +++ b/bin/secretmenu @@ -0,0 +1,85 @@ +#!/bin/bash + +set -eo pipefail +[ -n "$DEBUG" ] && set -x + +ico=$(iconez -fs -n dialog-password-symbolic) +trap '{ notify-send -a secretmenu -i "${ico}" -c error "secretmenu: failed :(" "pipefail"; exit 1; }' ERR + +if [ "$1" = "-b" ]; then + secretmgr=rbw + __list_secrets() { + rbw list + } + __query_secret() { + rbw get "$1" 2>&1 + } +else + secretmgr=pass + __list_secrets() { + prefix=${PASSWORD_STORE_DIR-~/.password-store} + prefix=$(readlink -f -- "${prefix}") + fd -e gpg . "${prefix}" | sed -e "s#${prefix}/##" -e 's#\.gpg$##' + } + __query_secret() { + pass show "$1" 2>&1 + } +fi + +__handle() { + awk 'NR==1 {system("wl-copy -n " $0);hit+=1} /^Username:/ {system("wl-copy -n -p " $2);hit+=1} END{if(hit==0) print("no secret found")}' +} + +# check requirements +for tool in bemenu fd fzf $secretmgr; do + if ! command -v "$tool" >/dev/null; then + printf "%s: %s not installed but required\n" "$(basename "$0")" "$tool" >&2 + exit 1 + fi +done + +# TODO: +# typeit= +# if [ "$1" = "--type" ]; then +# typeit=1 +# shift +# fi + +__menu() { + if [ ! -t 1 ]; then + MENU_PROMPT="󰌆 secret" menu + else + fzf + fi +} + +pw=$({ + __list_secrets + echo ">>pass" + echo ">>bw" +} | __menu "$@") + +case "$pw" in +"") exit 1 ;; +">>pass") exec "$0" ;; +">>bw") exec "$0" -b ;; +esac + +err=$(__query_secret "$pw" | __handle) + +# shellcheck disable=SC2181 +if [ "$?" -ne 0 ] || [ -n "$err" ]; then + notify-send \ + -a passmenu \ + -i "${ico}" \ + -c error \ + 'secretmenu: failed :(' \ + "${err}" + exit 1 +fi + +notify-send \ + -a secretmenu \ + -i "${ico}" \ + 'secretmenu: secret copied' \ + 'will be removed after next paste' -- cgit 1.4.1