summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Ball <nullspoon@oper.io>2017-07-11 08:50:50 -0600
committerAaron Ball <nullspoon@oper.io>2017-07-11 08:50:50 -0600
commited18399ed844789b161b947f3000fc393f85cc0d (patch)
tree039a711ebab9c6c479a95365070eab23baa72312
parentb0efff2df83158118b1a86598b02d13dd4441e67 (diff)
parentd37002a3c0b8eb9e2adb996f25a3b52e9adb8723 (diff)
downloadbin-ed18399ed844789b161b947f3000fc393f85cc0d.tar.gz
bin-ed18399ed844789b161b947f3000fc393f85cc0d.tar.xz
Merge branch 'pt-delim-submit'
-rwxr-xr-xpt51
1 files changed, 46 insertions, 5 deletions
diff --git a/pt b/pt
index bbbd491..91aa0cc 100755
--- a/pt
+++ b/pt
@@ -60,23 +60,64 @@ function check_env {
}
+#
+# Gets a field's value from the specified [multiline] string, using the
+# specified delimiter.
+#
+# @param content Content to extract field value from
+# @param delim Delimiter seperating fields and values
+# @param field Field name to get value for
+#
+getfield() {
+ local _content="${1:-}"
+ local _delim="${2:-}"
+ local _field="${3:-}"
+
+ printf "${_content}" \
+ | sed -n "s/${_field}${_delim} *\(.*\)/\1/p" \
+ | head -n 1
+}
+
+
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 _delim=Tab # Default delimiter if not specified in pass entry
+ local _submit=0 # Default submit value if not specified in pass entry
+
# Exit failure if no password was specified
[[ -z ${1} ]] && log "Please specify a password to be typed" && exit 1
check_env || exit 0
# Check if the password exists in the store
- pass ${@} &> /dev/null
+ # Also, copy the contents into a variable if it exists
+ _passentry=$(pass ${@} 2>/dev/null)
[[ $? -gt 0 ]] && log "Error: '${@}' is not in the password store" && exit 1
# Parse pass output into appropriate variables
- local passfile="$(pass ${@})"
- local username=$(echo -e "${passfile}" | sed -n 's/username: \(.*\)/\1/p' | head -n 1)
- local pass=$(echo -e "${passfile}" | head -n 1)
+ _passpassword=$(printf "${_passentry}" | head -n1)
+ _passusername=$(getfield "${_passentry}" ':' username)
+ _passdelim=$(getfield "${_passentry}" ':' delim)
+ _passsubmit=$(getfield "${_passentry}" ':' submit)
+
+ # If any of the known 'submit' values are specified, set submit to 1
+ if [ "${_passsubmit}" = '1' ] \
+ || [ "${_passsubmit}" = 'y' ] \
+ || [ "${_passsubmit}" = 'yes' ]; then
+ _submit=1
+ fi
# Type the password
- xdotool type --delay 15 "${username} ${pass}"
+ xdotool type --delay 15 "${_passusername}"
+ xdotool key "${_delim}"
+ xdotool type --delay 15 "${_passpassword}"
+
+ [ "${_submit}" = 1 ] && xdotool key Return
}
main ${@}

Generated by cgit