From 89cef20b3cdc113cad3d68b44bc436444f16d41d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Eug=C3=AAnio?= Date: Mon, 7 Aug 2023 19:58:05 -0300 Subject: [PATCH] pass: enable otp generation --- scripts/default.nix | 4 ++++ scripts/wpass | 16 +++++++++++++++- user/fish/completions/pass.fish | 2 ++ user/pass.nix | 9 +++++++-- 4 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 user/fish/completions/pass.fish diff --git a/scripts/default.nix b/scripts/default.nix index 11086dd..844308b 100644 --- a/scripts/default.nix +++ b/scripts/default.nix @@ -19,6 +19,10 @@ let })); create_scripts = lib.mapAttrs (name: deps: create_script name ./${name} deps); + + pass = pkgs.pass.withExtensions (ex: with ex; [ + pass-otp + ]); in create_scripts { diff --git a/scripts/wpass b/scripts/wpass index b635e35..7aefd24 100644 --- a/scripts/wpass +++ b/scripts/wpass @@ -9,6 +9,17 @@ find_file() { 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() { test -n "$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): (.*)/'` 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 Autotype) @@ -31,6 +43,8 @@ main() { printf '%s' "$username" | wl-copy;; Password) printf '%s' "$password" | wl-copy;; + OTP) + pass otp "$entry" | wl-copy;; esac } diff --git a/user/fish/completions/pass.fish b/user/fish/completions/pass.fish new file mode 100644 index 0000000..e0506a9 --- /dev/null +++ b/user/fish/completions/pass.fish @@ -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' diff --git a/user/pass.nix b/user/pass.nix index 5ad39ec..437ad1a 100644 --- a/user/pass.nix +++ b/user/pass.nix @@ -1,10 +1,15 @@ { config, pkgs, lib, inputs, ... }: { config = { - programs.password-store.enable = true; + programs.password-store = { + enable = true; + package = pkgs.pass.withExtensions (ex: with ex; [ + pass-otp + ]); + }; services = { pass-secret-service.enable = true; password-store-sync.enable = true; }; - home.packages = with pkgs; [ pass wpass _gpg-unlock ]; + home.packages = with pkgs; [ wpass _gpg-unlock ]; }; }