#!/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'