added better help message and intelligent squashing
This commit is contained in:
parent
16b747fc50
commit
7aa90cda15
57
wofi-pass
57
wofi-pass
@ -1,7 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
shopt -s nullglob globstar
|
||||
|
||||
_trim() {
|
||||
local var="$*"
|
||||
# remove leading whitespace characters
|
||||
@ -12,19 +10,24 @@ _trim() {
|
||||
}
|
||||
|
||||
_parse_fields() {
|
||||
has_username=0
|
||||
IFS=$'\n'
|
||||
fields="$(pass show $password | tail -n +2 | cut -d: -f1 -s)"
|
||||
if [[ $typeit -eq 1 ]]; then
|
||||
printf "autotype\n"
|
||||
fi
|
||||
printf "password\n"
|
||||
field_list+="password\n"
|
||||
for line in $fields; do
|
||||
if [[ $line == "otpauth" ]]; then
|
||||
printf "OTP\n"
|
||||
if [[ $line == "username" ]]; then
|
||||
has_username=1
|
||||
field_list+="$line\n"
|
||||
elif [[ $line == "otpauth" ]]; then
|
||||
field_list+="OTP\n"
|
||||
else
|
||||
printf "$line\n"
|
||||
field_list+="$line\n"
|
||||
fi
|
||||
done
|
||||
if [[ $typeit -eq 1 ]] && [[ $has_username -eq 1 ]]; then
|
||||
printf "autotype\n"
|
||||
fi
|
||||
printf "$field_list"
|
||||
unset IFS
|
||||
}
|
||||
|
||||
@ -49,10 +52,30 @@ _pass_get() {
|
||||
fi
|
||||
}
|
||||
|
||||
typeit=0
|
||||
if [[ $1 == "--type" ]]; then
|
||||
typeit=1
|
||||
shift
|
||||
_usage() {
|
||||
printf "Usage: wofi-pass [options]\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 " -t, --type type the selection instead of copying to clipboard\n"
|
||||
}
|
||||
|
||||
shopt -s nullglob globstar
|
||||
|
||||
OPTS="$(getopt --options hst --longoptions help,squash-choice,type -n 'wofi-pass' -- "$@")"
|
||||
eval set -- "$OPTS"
|
||||
while true; do
|
||||
case "$1" in
|
||||
-h | --help ) help=1; shift ;;
|
||||
-s | --squash-choice) squash=1; shift ;;
|
||||
-t | --type ) typeit=1; shift;;
|
||||
-- ) shift; break ;;
|
||||
* ) break ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [[ $help -eq 1 ]]; then
|
||||
echo "$(_usage)" >&2
|
||||
exit 0
|
||||
fi
|
||||
|
||||
prefix=${PASSWORD_STORE_DIR-~/.password-store}
|
||||
@ -63,8 +86,12 @@ password_files=( "${password_files[@]%.gpg}" )
|
||||
password=$(printf '%s\n' "${password_files[@]}" | wofi --dmenu "$@")
|
||||
[[ -n $password ]] || exit
|
||||
field_list="$(_parse_fields)"
|
||||
field=$(printf "$field_list" | wofi --dmenu)
|
||||
echo $field
|
||||
field_count="$(echo "$field_list" | wc -l)"
|
||||
if [[ squash -eq 1 ]] && [[ field_count -eq 1 ]]; then
|
||||
field="password"
|
||||
else
|
||||
field=$(printf "$field_list" | wofi --dmenu)
|
||||
fi
|
||||
|
||||
if [[ $typeit -eq 0 ]]; then
|
||||
wl-copy "$(_pass_get $field)"
|
||||
|
Reference in New Issue
Block a user