diff options
| author | JP Appel <jeanpierre.appel01@gmail.com> | 2025-07-11 12:57:47 -0400 |
|---|---|---|
| committer | JP Appel <jeanpierre.appel01@gmail.com> | 2025-07-11 12:57:47 -0400 |
| commit | 8e2485b1146655a6b75568f3edf8d2864d32dbda (patch) | |
| tree | 76c7650040eb80acec8c9388a1611071a518a8bb /scripts | |
| parent | af4fd3b1df0e1bfade496998dc7444cbeb1ae6a1 (diff) | |
Add dmenu script for otp's
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/passotpmenu | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/scripts/passotpmenu b/scripts/passotpmenu new file mode 100755 index 0000000..3886788 --- /dev/null +++ b/scripts/passotpmenu @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +shopt -s nullglob globstar + +typeit=0 +if [[ $1 == "--type" ]]; then + typeit=1 + shift +fi + +if [[ -n $WAYLAND_DISPLAY ]]; then + dmenu=dmenu-wl + xdotool="ydotool type --file -" +elif [[ -n $DISPLAY ]]; then + dmenu=dmenu + xdotool="xdotool type --clearmodifiers --file -" +else + echo "Error: No Wayland or X11 display detected" >&2 + exit 1 +fi + +prefix=${PASSWORD_STORE_DIR-~/.password-store} +password_files=( "$prefix"/**/*.gpg ) +password_files=( "${password_files[@]#"$prefix"/}" ) +password_files=( "${password_files[@]%.gpg}" ) + +password=$(printf '%s\n' "${password_files[@]}" | "$dmenu" "$@") + +[[ -n $password ]] || exit + +if [[ $typeit -eq 0 ]]; then + pass otp -c "$password" 2>/dev/null +else + pass otp "$password" | { IFS= read -r pass; printf %s "$pass"; } | $xdotool +fi |
