Created
January 1, 2016 18:55
-
-
Save allo-/22b3bd6b34d4bbcc26ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
sleep 1 | |
windowid="$(xdotool getactivewindow)" | |
windowname="$(xdotool getwindowname "$windowid")" | |
declare -a matching_titles | |
for folder in $HOME/.password-store/autotype/*;do | |
window_folder="$(basename "$folder")"; | |
if grep -qFi "$window_folder" <<<"$windowname";then | |
matching_titles+=("$window_folder") | |
fi; | |
done | |
declare -A passwords | |
for i in "${!matching_titles[@]}";do | |
title="${matching_titles[$i]}" | |
for passwordfile in "$HOME/.password-store/autotype/$title/"*.gpg;do | |
password=$(basename "$passwordfile"); | |
password="${password%.gpg}" | |
passwords[("$title/$password")]="autotype/$title/$password" | |
done; | |
done; | |
if [ "${#passwords[@]}" -eq "1" ];then | |
username_password=$(pass show "${passwords[@]}") | |
elif [ "${#passwords[@]}" -eq "0" ];then | |
kdialog --passivepopup "No passwords found" 1 | |
exit 0 | |
else | |
entries=""; | |
for key in "${!passwords[@]}";do | |
if [ "$entries" = "" ];then | |
entries="$key\0${passwords[$key]}" | |
else | |
entries="$entries\0$key\0${passwords[$key]}" | |
fi | |
done | |
key=$(echo -ne "$entries"|xargs -0 kdialog --geometry 500x200 --menu "Multiple matches") | |
if [ "$?" != "0" ];then # canceled | |
exit 0 | |
fi; | |
password_key="${passwords[$key]}" | |
IFS="" username_password="$(pass show "$password_key")" | |
declare -a lines | |
fi | |
while read -r line;do | |
lines+=("$line") | |
done <<<"$username_password" | |
num_lines="${#lines[@]}" | |
last_line=$((num_lines - 1)) | |
for key in "${!lines[@]}";do | |
xdotool type --clearmodifiers "${lines["$key"]}" | |
if [ "$key" != "$last_line" ];then | |
xdotool key Tab; | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See https://github.com/allo-/passautotype for the new version in python.