diff options
Diffstat (limited to 'bin/secretmenu')
| -rwxr-xr-x | bin/secretmenu | 53 |
1 files changed, 28 insertions, 25 deletions
diff --git a/bin/secretmenu b/bin/secretmenu index 386d870..8c447fb 100755 --- a/bin/secretmenu +++ b/bin/secretmenu @@ -22,11 +22,33 @@ while getopts bpPh name; do done shift $((OPTIND - 1)) +# check requirements +for tool in bemenu fd flock 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 + +# ensure only one menu runs at a time +lockfile="$XDG_RUNTIME_DIR"/secretmenu.lock +[ "$FLOCKER" != "$lockfile" ] && exec env FLOCKER="$lockfile" flock -ew 30 "$lockfile" "$0" "$@" +trap '{ env UNSAFE=1 rm $lockfile 2>/dev/null || true; }' EXIT TERM INT + +__menu() { + if [ -t 1 ]; then + echo "terminal mode not implemented" + exit 1 + fi + MENU_PROMPT=" secret" menu --list=10 --accept-single ${@:+--filter "$@"} +} + if [ "$secretmgr" = "rbw" ] && command -v rbw >/dev/null 2>&1; then __list_secrets() { - rbw list --fields name,user,id | column -t -s $'\t' + rbw list --fields name,user,folder,id | column -t -s $'\t' } __query_secret() { + # query by the last space-separated item (id) rbw get --full -- "${1##* }" 2>&1 } fi @@ -52,28 +74,7 @@ else } fi -# 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 - echo "terminal mode not implemented" - exit 1 - fi - MENU_PROMPT=" secret" menu --list=10 --accept-single ${@:+--filter "$@"} -} +# main pw=$({ __list_secrets @@ -89,9 +90,11 @@ case "$pw" in esac __query_secret "$pw" | __handle +__ok=$? + +[ -n "$printpass" ] && exit "$__ok" -# shellcheck disable=SC2181 -if [ "$?" -eq 0 ]; then +if [ "$__ok" -eq 0 ]; then notify-send \ -a secretmenu \ -i "${ico}" \ |