Skip to content

Instantly share code, notes, and snippets.

@allo-
Created January 1, 2016 18:55
Show Gist options
  • Save allo-/22b3bd6b34d4bbcc26ef to your computer and use it in GitHub Desktop.
Save allo-/22b3bd6b34d4bbcc26ef to your computer and use it in GitHub Desktop.
#!/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
@allo-
Copy link
Author

allo- commented Jan 1, 2016

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:

  • Enter after last line?
  • Use a filename as username?
  • Sanitize more parts of the bash script.
  • Allow more Keyboard scripting sequences (username, ENTER, WAIT, password, ENTER)

See also:

@allo-
Copy link
Author

allo- commented Jan 4, 2016

See https://github.com/allo-/passautotype for the new version in python.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment