add script and README

This commit is contained in:
Joel Beckmeyer 2020-03-27 22:55:38 -04:00
parent 2a91c4334c
commit eacb4ff7af
2 changed files with 111 additions and 0 deletions

31
README.md Normal file
View File

@ -0,0 +1,31 @@
# wofi-pass
Since `wofi` isn't a drop-in replacement for `rofi`, I couldn't use
[rofi-pass](https://github.com/carnager/rofi-pass) anymore. So, I just made a
version of `passmenu` that accomplishes everything I needed from `rofi-pass`.
## What does it do?
This script uses [wofi](https://hg.sr.ht/~scoopta/wofi) and
[ydotool](https://github.com/ReimuNotMoe/ydotool) to provide a completely
Wayland-native way to conveniently use [pass](https://www.passwordstore.org/).
It provides the same search that `passmenu` does, but shows a second dialogue
that lets the user choose which field to copy/print.
It also assumes that [pass-otp](https://github.com/tadfisher/pass-otp) is
installed if an `otpauth://...` string is present in a password file.
The script assumes several things:
1. The password is on the first line;
2. The rest of the lines are formatted as key:value pairs.
See the following example:
```
Th3Gr3at3stPassw0rd
username: JohnDoe
email: john@example.com
otpauth://totp/example?secret=ABCDCBABCDCBABCD
pin: 1234
```
I know this script needs some work; it was mostly hacked together in an
afternoon to get the minimum functionality I needed.

80
wofi-pass Executable file
View File

@ -0,0 +1,80 @@
#!/usr/bin/env bash
shopt -s nullglob globstar
_trim() {
local var="$*"
# remove leading whitespace characters
var="${var#"${var%%[![:space:]]*}"}"
# remove trailing whitespace characters
var="${var%"${var##*[![:space:]]}"}"
printf '%s' "$var"
}
_parse_fields() {
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"
for line in $fields; do
if [[ $line == "otpauth" ]]; then
printf "OTP\n"
else
printf "$line\n"
fi
done
unset IFS
}
_pass_field() {
IFS=$'\n'
plaintext="$(pass show $password | tail -n +2)"
for line in $plaintext; do
if [[ $line == $1:* ]]; then
printf "$(_trim "$(printf "$line" | cut -d: -f2 -s)")"
fi
done
unset IFS
}
_pass_get() {
if [[ $1 == "password" ]]; then
pass show "$password" | { IFS= read -r pass; printf %s "$pass"; }
elif [[ $1 == "OTP" ]]; then
pass otp "$password" | tail -n1 | { IFS= read -r pass; printf %s "$pass"; }
else
printf "$(_pass_field $1)"
fi
}
typeit=0
if [[ $1 == "--type" ]]; then
typeit=1
shift
fi
prefix=${PASSWORD_STORE_DIR-~/.password-store}
password_files=( "$prefix"/**/*.gpg )
password_files=( "${password_files[@]#"$prefix"/}" )
password_files=( "${password_files[@]%.gpg}" )
password=$(printf '%s\n' "${password_files[@]}" | wofi -i --dmenu "$@")
[[ -n $password ]] || exit
field_list="$(_parse_fields)"
field=$(printf "$field_list" | wofi -i --dmenu)
echo $field
if [[ $typeit -eq 0 ]]; then
wl-copy "$(_pass_get $field)"
else
if [[ $field == "autotype" ]]; then
_pass_get "username" | ydotool type --file -
printf "\t" | ydotool type --file -
_pass_get "password" | ydotool type --file -
printf "\n" | ydotool type --file -
else
_pass_get $field | ydotool type --file -
fi
fi