#!/bin/bash

list_passwords() {
	basedir=~/.password-store/
	passwords=( ~/.password-store/**/*.gpg ~/.password-store/*.gpg )
	for password in "${passwords[@]}"
	do
		filename="${password#$basedir}"
		filename="${filename%.gpg}"
		echo $filename
	done
}

xdotool_command() {
	echo -n "type "
	pass "$1"
}

selected_password="$(list_passwords 2>/dev/null| dmenu)"

echo $selected_password
if [ -n "$selected_password" ]
then
	xdotool_command "$selected_password" | xdotool -
fi
