Skip to content

Instantly share code, notes, and snippets.

@ivyl
Created November 12, 2013 11:46
Show Gist options
  • Save ivyl/7429582 to your computer and use it in GitHub Desktop.
Save ivyl/7429582 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -ue
if ! command -v xdotool &> /dev/null; then
printf "You need to install xdotool.\n" 1>&2
exit 1
fi
output="$(pass $@)"
exit_code="$?"
if [[ "$exit_code" -gt 0 ]]; then
exit "$exit_code"
fi
password="$(printf "%s" "$output" | head -n 1)"
username="$(printf "%s" "$output" | grep '^username: ' | cut -c 11-)"
active_window_id="$(xdotool getactivewindow)"
if [[ -n "$password" ]]; then
if [[ -n "$username" ]]; then
xdotool type --window "$active_window_id" "$username"
xdotool key --window "$active_window_id" "Tab"
xdotool type --window "$active_window_id" "i"
fi
xdotool type --window "$active_window_id" "$password"
fi
#!/usr/bin/env zsh
set -ue
local password_store="$HOME/.dotfiles/password-store"
if [[ ! -d "$password_store" ]]; then
printf "Configure \$password_store within $(command -v dmenu-pass-autotype).\n" 1>&2
printf "Its default location, $password_store, does not exist.\n" 1>&2
exit 1
fi
local candidates="$(find "$password_store" -name '*gpg' -print0 |
tr "\0" "\n" |
sed "s#$password_store/##;s#\.gpg\$##")"
local choice="$(printf "$candidates" | sort | dmenu -p 'pass-autotype' )"
if [[ -n "$choice" ]]; then
printf "Using $choice.\n" 1>&2
exec ~/.dotfiles/bin/pass-autotype "$choice" $*
else
printf "Nothing choosen.\n" 1>&2
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment