diff options
| author | Robert Günzler <r@gnzler.io> | 2023-01-17 00:38:11 +0100 |
|---|---|---|
| committer | Robert Günzler <r@gnzler.io> | 2023-01-17 00:38:11 +0100 |
| commit | 43cbbc1646b636713bb46cd20203ef7f30a31764 (patch) | |
| tree | 7455b3561d4c67d9bdb80d4e4918d248a07db9ad | |
| parent | f749a802fea79432c70bf713abb8e35f7f92004c (diff) | |
bin/secretmenu: ensure only one menu runs at a time
Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to '')
| -rwxr-xr-x | .local/share/lock/locked.d/light.sh | 3 | ||||
| -rwxr-xr-x | .local/share/lock/locked.d/music.sh | 2 | ||||
| -rwxr-xr-x | .local/share/lock/unlocked.d/light.sh | 2 | ||||
| -rwxr-xr-x | .local/share/lock/unlocked.d/sync.sh | 3 | ||||
| -rwxr-xr-x | bin/secretmenu | 53 |
5 files changed, 38 insertions, 25 deletions
diff --git a/.local/share/lock/locked.d/light.sh b/.local/share/lock/locked.d/light.sh new file mode 100755 index 0000000..3c492b9 --- /dev/null +++ b/.local/share/lock/locked.d/light.sh @@ -0,0 +1,3 @@ +#!/bin/sh +light -O +light -S 1 diff --git a/.local/share/lock/locked.d/music.sh b/.local/share/lock/locked.d/music.sh new file mode 100755 index 0000000..4c647d5 --- /dev/null +++ b/.local/share/lock/locked.d/music.sh @@ -0,0 +1,2 @@ +#!/bin/sh +playerctl -s stop || true diff --git a/.local/share/lock/unlocked.d/light.sh b/.local/share/lock/unlocked.d/light.sh new file mode 100755 index 0000000..a17c3ab --- /dev/null +++ b/.local/share/lock/unlocked.d/light.sh @@ -0,0 +1,2 @@ +#!/bin/sh +light -I diff --git a/.local/share/lock/unlocked.d/sync.sh b/.local/share/lock/unlocked.d/sync.sh new file mode 100755 index 0000000..8ddcdf2 --- /dev/null +++ b/.local/share/lock/unlocked.d/sync.sh @@ -0,0 +1,3 @@ +#!/bin/sh +mailsync & +pimsync & 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}" \ |