Skip to content

Commit

Permalink
Rewrite script to be posix compliant
Browse files Browse the repository at this point in the history
This will allow other shells than bash to work
  • Loading branch information
rbuchberger committed Mar 26, 2024
1 parent 07f4121 commit d090045
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
22 changes: 13 additions & 9 deletions bin/rbw-menu
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
#!/usr/bin/env sh
set -eu
IFS='
'
# Creator: Robert Buchberger <robert@buchberger.cc>
# @robert@spacey.space
#
Expand All @@ -13,21 +15,23 @@ IFS=$'\n\t'
# - anything else will return the value of the query
# default: username

rbw unlocked &> /dev/null || rbw unlock
# Check if rbw is locked, redirect stderr and stdout to /dev/null. Unlock if
# necessary.
rbw unlocked >/dev/null 2>&1 || rbw unlock

query=${1:-username}

chosen_item=$(
# If RBW_MENU_COMMAND is set, use it to filter the list.
if declare -p RBW_MENU_COMMAND >&/dev/null; then
eval "rbw list | $RBW_MENU_COMMAND"
else # use wofi
# If RBW_MENU_COMMAND is unset, use wofi
if [ "${RBW_MENU_COMMAND:-}" = "" ]; then
rbw list | wofi --dmenu --matching fuzzy --insensitive --prompt "$query"
else
eval "rbw list | $RBW_MENU_COMMAND"
fi
)

# Exit if user didn't select anything
declare -p chosen_item >&/dev/null || exit 1
[ "$chosen_item" = "" ] && exit 1

case "$query" in
code)
Expand Down
7 changes: 7 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,10 @@ bindsym $mod+o exec rbw-menu code | wl-copy
## Using a different menu

By default, we use wofi. To change this, set the `RBW_MENU_COMMAND` environment variable to anything which can accept a list from STDIN, and return a single line from that list to STDOUT.

## Releases

- 1.0 - Initial release
- 1.1 - Remove bespoke OTP support, use `rbw code` instead
- 1.2 - Check for and handle locked vault
- 1.3 - Remove undocumented bash dependency; rewrite script to be POSIX sh compliant

0 comments on commit d090045

Please sign in to comment.