add option to use filename as username
This commit is contained in:
parent
8a517c5172
commit
42699fdbcb
22
wofi-pass
22
wofi-pass
@ -3,6 +3,7 @@
|
|||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
autotype=0
|
autotype=0
|
||||||
|
fileisuser=0
|
||||||
help=0
|
help=0
|
||||||
squash=0
|
squash=0
|
||||||
|
|
||||||
@ -24,6 +25,12 @@ _parse_fields() {
|
|||||||
fields="$(pass show "$password" | tail -n +2 | cut -d: -f1 -s)"
|
fields="$(pass show "$password" | tail -n +2 | cut -d: -f1 -s)"
|
||||||
field_list="password
|
field_list="password
|
||||||
"
|
"
|
||||||
|
if [ "$fileisuser" -eq 1 ]; then
|
||||||
|
has_username=1
|
||||||
|
line="username"
|
||||||
|
field_list="$field_list$line
|
||||||
|
"
|
||||||
|
fi
|
||||||
for line in $fields; do
|
for line in $fields; do
|
||||||
if [ "$line" = "username" ]; then
|
if [ "$line" = "username" ]; then
|
||||||
has_username=1
|
has_username=1
|
||||||
@ -55,6 +62,8 @@ _pass_get() {
|
|||||||
pass show "$password" | { IFS= read -r pass; printf %s "$pass"; }
|
pass show "$password" | { IFS= read -r pass; printf %s "$pass"; }
|
||||||
elif [ "$1" = "OTP" ]; then
|
elif [ "$1" = "OTP" ]; then
|
||||||
pass otp "$password" | tail -n1 | { IFS= read -r pass; printf %s "$pass"; }
|
pass otp "$password" | tail -n1 | { IFS= read -r pass; printf %s "$pass"; }
|
||||||
|
elif [ "$fileisuser" -eq 1 ] && [ "$1" = "username" ]; then
|
||||||
|
printf %s "$passname"
|
||||||
else
|
else
|
||||||
_pass_field "$@"
|
_pass_field "$@"
|
||||||
fi
|
fi
|
||||||
@ -63,16 +72,18 @@ _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 " -a, --autotype autotype whatever entry is chosen\n"
|
||||||
|
printf " -f, --fileisuser use the name of the password file as username\n"
|
||||||
printf " -h, --help show this help message\n"
|
printf " -h, --help show this help message\n"
|
||||||
printf " -s, --squash 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"
|
||||||
}
|
}
|
||||||
|
|
||||||
OPTS="$(getopt --options ahst --longoptions autotype,help,squash,type -n 'wofi-pass' -- "$@")"
|
OPTS="$(getopt --options afhst --longoptions autotype,fileisuser,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 ;;
|
-a | --autotype ) autotype=1; shift ;;
|
||||||
|
-f | --fileisuser ) fileisuser=1; shift;;
|
||||||
-h | --help ) help=1; shift ;;
|
-h | --help ) help=1; shift ;;
|
||||||
-s | --squash ) squash=1; shift ;;
|
-s | --squash ) squash=1; shift ;;
|
||||||
-t | --type ) TYPE_CMD="wtype -"; shift;;
|
-t | --type ) TYPE_CMD="wtype -"; shift;;
|
||||||
@ -91,6 +102,11 @@ password_files="$(find . -name "*.gpg" | sed "s/^\.\/\(.*\)\.gpg$/\1/")"
|
|||||||
|
|
||||||
password=$(printf '%s\n' "$password_files" | wofi --dmenu)
|
password=$(printf '%s\n' "$password_files" | wofi --dmenu)
|
||||||
[ -n "$password" ] || exit
|
[ -n "$password" ] || exit
|
||||||
|
|
||||||
|
if [ "$fileisuser" -eq 1 ]; then
|
||||||
|
passname=$(printf '%s' "$password" | sed "s,.*/\(\),\1,")
|
||||||
|
fi
|
||||||
|
|
||||||
field_list="$(_parse_fields)"
|
field_list="$(_parse_fields)"
|
||||||
field_count="$(printf '%s' "$field_list" | wc -l)"
|
field_count="$(printf '%s' "$field_list" | wc -l)"
|
||||||
if [ "$squash" -eq 1 ] && [ "$field_count" -eq 0 ]; then
|
if [ "$squash" -eq 1 ] && [ "$field_count" -eq 0 ]; then
|
||||||
@ -100,7 +116,11 @@ elif [ "$autotype" -ne 1 ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$field" = "autotype" ] || [ "$autotype" -eq 1 ]; then
|
if [ "$field" = "autotype" ] || [ "$autotype" -eq 1 ]; then
|
||||||
|
if [ "$fileisuser" -eq 1 ]; then
|
||||||
|
username="$passname"
|
||||||
|
else
|
||||||
username=$(_pass_get "username")
|
username=$(_pass_get "username")
|
||||||
|
fi
|
||||||
password=$(_pass_get "password")
|
password=$(_pass_get "password")
|
||||||
printf '%s\t%s\n' "$username" "$password" | $TYPE_CMD
|
printf '%s\t%s\n' "$username" "$password" | $TYPE_CMD
|
||||||
else
|
else
|
||||||
|
Reference in New Issue
Block a user