add autotype options

This commit is contained in:
Joel Beckmeyer 2020-04-08 12:25:53 -04:00
parent 3d3a3d0f3d
commit d183696e74

View File

@ -20,13 +20,12 @@ _parse_fields() {
field_list+="$line\n" field_list+="$line\n"
elif [[ $line == "otpauth" ]]; then elif [[ $line == "otpauth" ]]; then
field_list+="OTP\n" field_list+="OTP\n"
elif [[ $line == autotype_always ]]; then
autotype=1
else else
field_list+="$line\n" field_list+="$line\n"
fi fi
done done
if [[ $typeit -eq 1 ]] && [[ $has_username -eq 1 ]]; then
printf "autotype\n"
fi
printf "$field_list" printf "$field_list"
unset IFS unset IFS
} }
@ -54,19 +53,21 @@ _pass_get() {
_usage() { _usage() {
printf "Usage: wofi-pass [options]\n" printf "Usage: wofi-pass [options]\n"
printf " -a, --autotype autotype whatever entry is chosen\n"
printf " -h, --help show this help message\n" printf " -h, --help show this help message\n"
printf " -s, --squash-choice don't show field choice if password file only contains password\n" printf " -s, --squash don't show field choice if password file only contains password\n"
printf " -t, --type type the selection instead of copying to clipboard\n" printf " -t, --type type the selection instead of copying to clipboard\n"
} }
shopt -s nullglob globstar shopt -s nullglob globstar
OPTS="$(getopt --options hst --longoptions help,squash-choice,type -n 'wofi-pass' -- "$@")" OPTS="$(getopt --options ahst --longoptions autotype,help,squash,type -n 'wofi-pass' -- "$@")"
eval set -- "$OPTS" eval set -- "$OPTS"
while true; do while true; do
case "$1" in case "$1" in
-a | --autotype ) autotype=1; shift ;;
-h | --help ) help=1; shift ;; -h | --help ) help=1; shift ;;
-s | --squash-choice) squash=1; shift ;; -s | --squash ) squash=1; shift ;;
-t | --type ) typeit=1; shift;; -t | --type ) typeit=1; shift;;
-- ) shift; break ;; -- ) shift; break ;;
* ) break ;; * ) break ;;
@ -87,16 +88,16 @@ password=$(printf '%s\n' "${password_files[@]}" | wofi --dmenu "$@")
[[ -n $password ]] || exit [[ -n $password ]] || exit
field_list="$(_parse_fields)" field_list="$(_parse_fields)"
field_count="$(echo "$field_list" | wc -l)" field_count="$(echo "$field_list" | wc -l)"
if [[ squash -eq 1 ]] && [[ field_count -eq 1 ]]; then if [[ $squash -eq 1 ]] && [[ $field_count -eq 1 ]]; then
field="password" field="password"
else elif [[ $autotype -ne 1 ]]; then
field=$(printf "$field_list" | wofi --dmenu) field=$(printf "$field_list" | wofi --dmenu)
fi fi
if [[ $typeit -eq 0 ]]; then if [[ $typeit -eq 0 ]]; then
wl-copy "$(_pass_get $field)" wl-copy "$(_pass_get $field)"
else else
if [[ $field == "autotype" ]]; then if [[ $field == "autotype" ]] || [[ $autotype -eq 1 ]]; then
_pass_get "username" | ydotool type --file - _pass_get "username" | ydotool type --file -
printf "\t" | ydotool type --file - printf "\t" | ydotool type --file -
_pass_get "password" | ydotool type --file - _pass_get "password" | ydotool type --file -