Make passui typeable
3 files changed, 28 insertions(+), 34 deletions(-)

M .config/i3/config.base
M .config/sway/config
M bin/passui
M .config/i3/config.base +2 -1
@@ 48,7 48,8 @@ bindsym $mod+Shift+O exec shutdown
 # start dmenu (a program launcher)
 bindsym $mod+d exec $menu
 
-bindsym $mod+Shift+p exec $passmenu
+bindsym $mod+p exec $passmenu
+bindsym $mod+Shift+p exec $passmenu -t
 
 # change focus
 bindsym $mod+$left focus left

          
M .config/sway/config +2 -1
@@ 55,7 55,8 @@ bindsym $mod+Shift+O exec shutdown
 # start dmenu (a program launcher)
 bindsym $mod+d exec $menu
 
-bindsym $mod+Shift+p exec $passmenu
+bindsym $mod+p exec $passmenu
+bindsym $mod+Shift+p exec $passmenu -t
 
 # change focus
 bindsym $mod+$left focus left

          
M bin/passui +24 -32
@@ 1,37 1,29 @@ 
-#!/usr/bin/env bash
-
-shopt -s nullglob globstar
+#!/usr/bin/env sh
 
-typeit=0
-program="/usr/bin/bemenu"
+typeit=
+if [ "-t" = "$1" ]; then
+	typeit=1
+	shift
+fi
 
-usage() { echo "Usage: $0 [-h] [-t] [-p <rofi|bemenu>] [-a <string>]" 1>&2; exit 1; }
+prefix=${PASSWORD_STORE_DIR-$HOME/.password-store}
 
-while getopts ":ts:p:a:hs:" arg; do
-	case $arg in
-		t)
-			typeit=1
-			;;
-		a)
-			arguments=${OPTARG}
-			;;
-		h)
-			usage
-			;;
-	esac
-done
-shift $((OPTIND-1))
+password="$(
+	find "$prefix" -type f -name "*.gpg" | \
+		sort | \
+		sed -e "s|$prefix||" -e "s|^/||" -e "s|.gpg$||" | \
+		bemenu
+)"
+
+[ -z "$password" ] && exit
 
-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[@]}" | "$program" $arguments)
-
-[[ -n $password ]] || exit
-
-if [[ $typeit -eq 0 ]]; then
-	pass show -c "$password" 2>/dev/null
+if [ -n "$typeit" ]; then
+	if [ -n "$WAYLAND_DISPLAY" ]; then
+		wtype "$(basename "$password")" -k Tab "$(pass show "$password")"
+	else
+		echo "We can't type it" /dev/stderr
+		exit 1
+	fi
 else
-	pass show "$password" | { IFS= read -r pass; printf %s "$pass"; } fi
+	pass show -c "$password"
+fi