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
Install before:
Then create entries "autotype/WindowTitle/Login", i.e.
pass insert -m "autotype/Foo - Login/login"
Add two lines, the first is the username, the second the password. You can add more lines, after each line (except the last one), the autotype script will "press" tab.
When multiple titles and/or accounts match, you will get a list of possible Logins, i.e. these:
autotype/Github/mainaccount
autotype/Github/secondaccount
"autotype/Github - Where Software is built/yet another login"
You can symlink your existing passwords to
autotype/site title/account
.TODO:
See also: