Compare commits
9 Commits
397354e1ec
...
c5a5f300fb
Author | SHA1 | Date | |
---|---|---|---|
c5a5f300fb | |||
6de507d9d7 | |||
869c5450bd | |||
5fc2f0a242 | |||
29decbf0c2 | |||
15269b633a | |||
42699fdbcb | |||
8a517c5172 | |||
|
5c9fa17872 |
17
README.md
17
README.md
@ -1,10 +1,15 @@
|
|||||||
|
# ARCHIVED AS I NO LONGER REGULARLY USE THIS.
|
||||||
|
|
||||||
# wofi-pass
|
# wofi-pass
|
||||||
```
|
```
|
||||||
Usage: wofi-pass [options]
|
Usage: wofi-pass [options]
|
||||||
-a, --autotype autotype whatever entry is chosen
|
-a, --autotype autotype whatever entry is chosen
|
||||||
-h, --help show this help message
|
-c, --copy [cmd] copy to clipboard. Defaults to wl-copy if no cmd is given.
|
||||||
-s, --squash don't show field choice if password file only contains password
|
-f, --fileisuser use the name of the password file as username
|
||||||
-t, --type type the selection instead of copying to clipboard
|
-h, --help show this help message
|
||||||
|
-s, --squash don't show field choice if password file only contains password
|
||||||
|
-t, --type [cmd] type the selection instead of copying to clipboard.
|
||||||
|
Defaults to wtype if no cmd is given.
|
||||||
```
|
```
|
||||||
|
|
||||||
Since `wofi` isn't a drop-in replacement for `rofi`, I couldn't use
|
Since `wofi` isn't a drop-in replacement for `rofi`, I couldn't use
|
||||||
@ -37,7 +42,3 @@ the field choice dialogue when there is only a password in the file.
|
|||||||
The `-t | --type` flag tells `wofi-pass` to type the choice instead of copying
|
The `-t | --type` flag tells `wofi-pass` to type the choice instead of copying
|
||||||
to clipboard. This also enables the autotype choice which types
|
to clipboard. This also enables the autotype choice which types
|
||||||
`username :tab password`.
|
`username :tab password`.
|
||||||
|
|
||||||
## Disclaimer???
|
|
||||||
I know this script needs some work; it was mostly hacked together in an
|
|
||||||
afternoon to get the minimum functionality I needed.
|
|
||||||
|
108
wofi-pass
108
wofi-pass
@ -2,9 +2,16 @@
|
|||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
help=0
|
|
||||||
autotype=0
|
autotype=0
|
||||||
TYPE_CMD="wl-copy"
|
copyisset=0
|
||||||
|
fileisuser=0
|
||||||
|
help=0
|
||||||
|
onlypassword=0
|
||||||
|
squash=0
|
||||||
|
typeisset=0
|
||||||
|
|
||||||
|
COPY_CMD="wl-copy"
|
||||||
|
TYPE_CMD="wtype -"
|
||||||
|
|
||||||
_trim() {
|
_trim() {
|
||||||
var="$*"
|
var="$*"
|
||||||
@ -22,6 +29,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
|
||||||
@ -37,7 +50,7 @@ _parse_fields() {
|
|||||||
"
|
"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
if [ "$TYPE_CMD" = "wtype -" ] && [ "$has_username" -eq 1 ]; then
|
if [ "$typeisset" -eq 1 ] && [ "$has_username" -eq 1 ]; then
|
||||||
printf "autotype
|
printf "autotype
|
||||||
"
|
"
|
||||||
fi
|
fi
|
||||||
@ -53,6 +66,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
|
||||||
@ -60,22 +75,45 @@ _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 " -h, --help show this help message\n"
|
printf " -c, --copy=[cmd] copy to clipboard. Defaults to wl-copy if no cmd is given.\n"
|
||||||
printf " -s, --squash don't show field choice if password file only contains password\n"
|
printf " -f, --fileisuser use the name of the password file as username\n"
|
||||||
printf " -t, --type type the selection instead of copying to clipboard\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 " -t, --type=[cmd] type the selection instead of copying to clipboard.\n"
|
||||||
|
printf " Defaults to wtype if no cmd is given.\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
OPTS="$(getopt --options ahst --longoptions autotype,help,squash,type -n 'wofi-pass' -- "$@")"
|
OPTS="$(getopt --options ac::fhst:: --longoptions autotype,copy::,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 ;;
|
||||||
-h | --help ) help=1; shift ;;
|
-c ) copyisset=1; copy_cmd="$COPY_CMD"; shift ;;
|
||||||
-s | --squash ) squash=1; shift ;;
|
--copy )
|
||||||
-t | --type ) TYPE_CMD="wtype -"; shift;;
|
copyisset=1
|
||||||
-- ) shift; break ;;
|
if [ -n "$2" ]; then
|
||||||
* ) break ;;
|
copy_cmd="$2"
|
||||||
|
shift 2
|
||||||
|
else
|
||||||
|
copy_cmd="$COPY_CMD"
|
||||||
|
shift
|
||||||
|
fi ;;
|
||||||
|
-f | --fileisuser ) fileisuser=1; shift;;
|
||||||
|
-h | --help ) help=1; shift ;;
|
||||||
|
-s | --squash ) squash=1; shift ;;
|
||||||
|
-t ) typeisset=1; type_cmd="$TYPE_CMD"; shift ;;
|
||||||
|
--type )
|
||||||
|
typeisset=1
|
||||||
|
if [ -n "$2" ]; then
|
||||||
|
type_cmd="$2"
|
||||||
|
shift 2
|
||||||
|
else
|
||||||
|
type_cmd="$TYPE_CMD"
|
||||||
|
shift
|
||||||
|
fi ;;
|
||||||
|
-- ) shift; break;;
|
||||||
|
* ) break;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
@ -84,23 +122,55 @@ if [ "$help" -eq 1 ]; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ "$typeisset" -eq 1 ] && [ "$copyisset" -eq 1 ]; then
|
||||||
|
printf "copy and type cannot be used at same time. Please pass only one.\n"
|
||||||
|
exit 1
|
||||||
|
elif [ "$typeisset" -eq 0 ] && [ "$copyisset" -eq 0 ]; then
|
||||||
|
printf "neither -c/--copy or -t/--type passed. Defaulting to copying with wl-copy."
|
||||||
|
copy_cmd="$COPY_CMD"
|
||||||
|
fi
|
||||||
|
|
||||||
cd "${PASSWORD_STORE_DIR:-$HOME/.password-store}"
|
cd "${PASSWORD_STORE_DIR:-$HOME/.password-store}"
|
||||||
password_files="$(find . -name "*.gpg" | sed "s/^\.\/\(.*\)\.gpg$/\1/")"
|
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
|
||||||
field="password"
|
field="password"
|
||||||
|
onlypassword=1
|
||||||
elif [ "$autotype" -ne 1 ]; then
|
elif [ "$autotype" -ne 1 ]; then
|
||||||
field=$(printf '%s\n' "$field_list" | wofi --dmenu)
|
field=$(printf '%s\n' "$field_list" | wofi --dmenu)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$field" = "autotype" ] || [ "$autotype" -eq 1 ]; then
|
# get the command to output to
|
||||||
username=$(_pass_get "username")
|
if [ "$typeisset" -eq 1 ]; then
|
||||||
password=$(_pass_get "password")
|
output_cmd=$type_cmd
|
||||||
printf '%s\t%s\n' "$username" "$password" | $TYPE_CMD
|
|
||||||
else
|
else
|
||||||
_pass_get "$field" | $TYPE_CMD
|
output_cmd=$copy_cmd
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$autotype" -eq 1 ] || [ "$field" = "autotype" ]; then
|
||||||
|
if [ "$fileisuser" -eq 1 ]; then
|
||||||
|
username="$passname"
|
||||||
|
else
|
||||||
|
username=$(_pass_get "username")
|
||||||
|
fi
|
||||||
|
password=$(_pass_get "password")
|
||||||
|
|
||||||
|
# check if we are autotyping a password-only file
|
||||||
|
if [ "$onlypassword" -eq 1 ]; then
|
||||||
|
printf '%s\n' "$password" | $output_cmd
|
||||||
|
else
|
||||||
|
printf '%s\t%s\n' "$username" "$password" | $output_cmd
|
||||||
|
fi
|
||||||
|
|
||||||
|
else
|
||||||
|
_pass_get "$field" | $output_cmd
|
||||||
fi
|
fi
|
||||||
|
Reference in New Issue
Block a user