summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Ball <nullspoon@oper.io>2018-09-28 18:11:39 -0600
committerAaron Ball <nullspoon@oper.io>2018-09-28 18:26:42 -0600
commitefd616302e739feb9a1bb81466287f41506df4a5 (patch)
treefd58500c3acdbe06ca52ad4ac2c0b98a0ca8d5ce
parent9829b4d3d882c554255eeeea107ae0f858cfd866 (diff)
downloadbin-efd616302e739feb9a1bb81466287f41506df4a5.tar.gz
bin-efd616302e739feb9a1bb81466287f41506df4a5.tar.xz
pt:Implemented paste by default, with type override
Originally, typing passwords with xdotool was the only way to use the tool, primarily because some apps prevent the user from copying and pasting. Now we use copy and paste by default, because so few apps prevent that. To override default behavior of pasting username and password, set 'type=[1|y|yes|true]' in the pass entry. Note: the copy/paste process of username and password backs up current clipboard value and restores it after the username and password have been pasted.
-rwxr-xr-xpt69
1 files changed, 60 insertions, 9 deletions
diff --git a/pt b/pt
index dbbfab9..dc4b50a 100755
--- a/pt
+++ b/pt
@@ -79,15 +79,54 @@ getfield() {
}
+typefields() {
+ local _user="${1:-}"
+ local _pass="${2:-}"
+ local _delim="${3:-}"
+
+ # Type the password
+ xdotool type --delay 15 "${_user}"
+ xdotool key "${_delim}"
+ xdotool type --delay 15 "${_pass}"
+}
+
+
+pastefields() {
+ local _user="${1:-}"
+ local _pass="${2:-}"
+ local _delim="${3:-}"
+
+ # Save clipboard first
+ local _origclipboard="$(xclip -o -selection clipboard)"
+
+ # Sleep .2 for those apps that read only "key up" events without first reading
+ # "key down", causing it to read pressing enter to execute pt as submitting
+ # the form (bad js devs, bad!).
+ sleep .2
+ # Save username to clipboard and paste
+ printf -- "%s\n" "${_user}" | xclip -selection clipboard
+ xdotool key "Control+v" "${_delim}"
+
+ # Save password to clipboard and paste
+ printf -- "%s\n" "${_pass}" | xclip -selection clipboard
+ xdotool key "Control+v"
+
+ # Restore original clipboard value
+ printf -- "%s\n" "${_origclipboard}" | xclip -selection clipboard
+}
+
+
function main {
local _passentry # Contents of the requested pass entry
local _passpassword # Password from the pass entry
local _passusername # Username field from the pass entry
local _passdelim # UI Field delimiter (Tab, Return), from the pass entry
local _passsubmit # Boolean submit (1,y,yes...), from the pass entry
+ local _passtype # Boolean type (1,y,yes...), from the pass entry
local _delim=Tab # Default delimiter if not specified in pass entry
local _submit=0 # Default submit value if not specified in pass entry
+ local _type=0 # Whether or not to type or paste (type=0 will paste)
# Exit failure if no password was specified
[[ -z ${1} ]] && log "Please specify a password to be typed" && exit 1
@@ -101,22 +140,34 @@ function main {
# Parse pass output into appropriate variables
_passpassword=$(printf -- "%s" "${_passentry}" | head -n1 | sed 's/`/\`/g')
- _passusername=$(getfield "${_passentry}" ':' username)
- _passdelim=$(getfield "${_passentry}" ':' delim)
- _passsubmit=$(getfield "${_passentry}" ':' submit)
+ _passusername=$(getfield "${_passentry}" ':' 'username')
+ _passdelim=$(getfield "${_passentry}" ':' 'delim')
+ _passsubmit=$(getfield "${_passentry}" ':' 'submit')
+ _passtype=$(getfield "${_passentry}" ':' 'type')
# If any of the known 'submit' values are specified, set submit to 1
if [ "${_passsubmit}" = '1' ] \
|| [ "${_passsubmit}" = 'y' ] \
- || [ "${_passsubmit}" = 'yes' ]; then
+ || [ "${_passsubmit}" = 'yes' ] \
+ || [ "${_passsubmit}" = 'true' ]; then
_submit=1
fi
-
- # Type the password
- xdotool type --delay 20 "${_passusername}"
- xdotool key "${_delim}"
- xdotool type --delay 20 "${_passpassword}"
+ # If any of the known 'type' values are specified, set type to 1
+ if [ "${_passtype}" = '1' ] \
+ || [ "${_passtype}" = 'y' ] \
+ || [ "${_passtype}" = 'yes' ] \
+ || [ "${_passtype}" = 'true' ]; then
+ _type=1
+ fi
+
+ # Type username/password if type == 1, otherwise paste username/password
+ if [ "${_type}" = '1' ]; then
+ typefields "${_passusername}" "${_passpassword}" "${_delim}"
+ else
+ pastefields "${_passusername}" "${_passpassword}" "${_delim}"
+ fi
+
[ "${_submit}" = 1 ] && xdotool key Return
}

Generated by cgit