m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2020-05-31 12:17:41 +0200
committerMarcin Chrzanowski <m@m-chrzan.xyz>2022-07-01 08:33:57 +0200
commit667e72fe88e66fa734ba0b5b20fe2834df9f4c18 (patch)
tree13a76238b10a02a076dc26de6e5f1b449254e7e0 /contrib
parentc4d8a1d815e79ddd89a85d3e36a41d29f0475771 (diff)
Add support for pass-otp in passmenu
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/dmenu/passmenu39
1 files changed, 33 insertions, 6 deletions
diff --git a/contrib/dmenu/passmenu b/contrib/dmenu/passmenu
index 76d92ab..18b2daf 100755
--- a/contrib/dmenu/passmenu
+++ b/contrib/dmenu/passmenu
@@ -3,10 +3,19 @@
shopt -s nullglob globstar
typeit=0
-if [[ $1 == "--type" ]]; then
- typeit=1
- shift
-fi
+otp=0
+infer_otp=0
+otp_pattern=""
+while [[ $# -gt 0 ]]; do
+ argument="$1"
+ shift
+ case $argument in
+ --type) typeit=1 ;;
+ --otp) otp=1 ;;
+ --infer-otp) infer_otp=1 ;;
+ --otp-pattern) otp_pattern="$1"; shift ;;
+ esac
+done
if [[ -n $WAYLAND_DISPLAY ]]; then
dmenu=dmenu-wl
@@ -24,12 +33,30 @@ password_files=( "$prefix"/**/*.gpg )
password_files=( "${password_files[@]#"$prefix"/}" )
password_files=( "${password_files[@]%.gpg}" )
+if [[ $otp -eq 1 ]]; then
+ filtered_files=()
+ for file in "${password_files[@]}"; do
+ [[ "$file" =~ $otp_pattern ]] && filtered_files+=("$file")
+ done
+ password_files=(${filtered_files[@]})
+fi
+
password=$(printf '%s\n' "${password_files[@]}" | "$dmenu" "$@")
[[ -n $password ]] || exit
+if [[ $infer_otp -eq 1 ]]; then
+ [[ "$password" =~ $otp_pattern ]] && otp=1
+fi
+
+otp_arg=''
+if [[ $otp -eq 1 ]]; then
+ otp_arg='otp'
+fi
+
if [[ $typeit -eq 0 ]]; then
- pass show -c "$password" 2>/dev/null
+ pass $otp_arg show -c "$password" 2>/dev/null
else
- pass show "$password" | { IFS= read -r pass; printf %s "$pass"; } | $xdotool
+ pass $otp_arg show "$password" | { IFS= read -r pass; printf %s "$pass"; } |
+ $xdotool
fi