pass: enable otp generation

This commit is contained in:
Leonardo Eugênio 2023-08-07 19:58:05 -03:00
parent 4ad060e795
commit 89cef20b3c
4 changed files with 28 additions and 3 deletions

View file

@ -19,6 +19,10 @@ let
})); }));
create_scripts = create_scripts =
lib.mapAttrs (name: deps: create_script name ./${name} deps); lib.mapAttrs (name: deps: create_script name ./${name} deps);
pass = pkgs.pass.withExtensions (ex: with ex; [
pass-otp
]);
in in
create_scripts create_scripts
{ {

View file

@ -9,6 +9,17 @@ find_file() {
wdmenu -p "Password" $@ wdmenu -p "Password" $@
} }
print_actions_for_entry() {
echo "Autotype"
if test -n "$username"; then
echo "Username -> $username"
fi
echo "Password"
if test -n "$otp"; then
echo "OTP"
fi
}
main() { main() {
test -n "$PASSWORD_STORE_DIR" && test -n "$PASSWORD_STORE_DIR" &&
cd "$PASSWORD_STORE_DIR" || cd "$PASSWORD_STORE_DIR" ||
@ -20,8 +31,9 @@ main() {
username=`pass show "$entry" 2>/dev/null | perl -ne 'print $2 if /^(login|user|email): (.*)/'` username=`pass show "$entry" 2>/dev/null | perl -ne 'print $2 if /^(login|user|email): (.*)/'`
password=`pass show "$entry" 2>/dev/null | head -n 1` password=`pass show "$entry" 2>/dev/null | head -n 1`
otp=`pass otp "$entry" 2>/dev/null`
action=`printf "Autotype\nUsername -> $username\nPassword" | wdmenu -p Action` action="$(print_actions_for_entry | wdmenu -p Action)"
case $action in case $action in
Autotype) Autotype)
@ -31,6 +43,8 @@ main() {
printf '%s' "$username" | wl-copy;; printf '%s' "$username" | wl-copy;;
Password) Password)
printf '%s' "$password" | wl-copy;; printf '%s' "$password" | wl-copy;;
OTP)
pass otp "$entry" | wl-copy;;
esac esac
} }

View file

@ -0,0 +1,2 @@
complete -c $PROG -f -n '__fish_pass_needs_command' -s c -l clip -d 'Generate an OTP code'
complete --no-files pass -a '(__fish_pass_print_entries)' -n '__fish_pass_uses_command otp'

View file

@ -1,10 +1,15 @@
{ config, pkgs, lib, inputs, ... }: { { config, pkgs, lib, inputs, ... }: {
config = { config = {
programs.password-store.enable = true; programs.password-store = {
enable = true;
package = pkgs.pass.withExtensions (ex: with ex; [
pass-otp
]);
};
services = { services = {
pass-secret-service.enable = true; pass-secret-service.enable = true;
password-store-sync.enable = true; password-store-sync.enable = true;
}; };
home.packages = with pkgs; [ pass wpass _gpg-unlock ]; home.packages = with pkgs; [ wpass _gpg-unlock ];
}; };
} }