diff --git a/flake.nix b/flake.nix index 474d245..44915a5 100644 --- a/flake.nix +++ b/flake.nix @@ -118,6 +118,7 @@ inherit (pkgs) keyboard-switch + rbw-fzf wl-clipedit wl-lockscreen wl-update-background @@ -178,6 +179,7 @@ packages = self: _super: { keyboard-switch = self.callPackage ./pkgs/keyboard-switch { }; wl-clipedit = self.callPackage ./pkgs/wl-clipedit { }; + rbw-fzf = self.callPackage ./pkgs/rbw-fzf { }; wl-lockscreen = self.callPackage ./pkgs/wl-lockscreen { }; wl-update-background = self.callPackage ./pkgs/wl-update-background { }; }; diff --git a/hm/hyprland.nix b/hm/hyprland.nix index bcf6398..bda0e35 100644 --- a/hm/hyprland.nix +++ b/hm/hyprland.nix @@ -29,6 +29,7 @@ in hyprpaper networkmanagerapplet playerctl + rbw-fzf sirula # swaylock swww @@ -228,7 +229,8 @@ in "SUPER, P, pseudo, # dwindle" "SUPER, J, togglesplit, # dwindle" "SUPER ALT, E, exec, wofi-emoji" - "SUPER ALT, P, exec, wl-clipedit" + "SUPER ALT, P, exec, foot wl-clipedit" + "SUPER ALT, I, exec, foot rbw-fzf" "SUPER ALT, B, exec, systemctl --user reload-or-restart wl-update-background" ",Print, exec, grimblast copy" "SHIFT, Print, exec, grimblast copy area" diff --git a/instances/sif/hm.nix b/instances/sif/hm.nix index a182e0c..f479403 100644 --- a/instances/sif/hm.nix +++ b/instances/sif/hm.nix @@ -46,6 +46,7 @@ pavucontrol procps protonvpn-gui + rbw # spotify telegram-desktop wiremix diff --git a/instances/thor/hm.nix b/instances/thor/hm.nix index 9340ca6..c302a40 100644 --- a/instances/thor/hm.nix +++ b/instances/thor/hm.nix @@ -50,6 +50,7 @@ pavucontrol procps protonvpn-gui + rbw # spotify telegram-desktop thunderbird diff --git a/pkgs/rbw-fzf/default.nix b/pkgs/rbw-fzf/default.nix new file mode 100644 index 0000000..6d9722d --- /dev/null +++ b/pkgs/rbw-fzf/default.nix @@ -0,0 +1,87 @@ +{ writeShellScriptBin +, lib +, wl-clipboard +, rbw +, fzf +, pinentry-gtk2 +}: +writeShellScriptBin "rbw-fzf" '' + PATH=$PATH:"${ lib.makeBinPath [ fzf rbw wl-clipboard pinentry-gtk2 ] }" + + # Check if the selected entry exists + get_entry () { + NAME=$(rbw ls | fzf) + + if [ $? -eq 1 ]; then + printf '%s\n' "Please, select a valid entry." + exit 1 + elif [ -z "$NAME" ]; then + printf '%s\n' "No entry selected, quitting." + exit 0 + else + get_username + fi + } + + get_username () { + # If the selected entry has a username, copy it to clipboard and ask if user also wants to copy the password + USERNAME=$(rbw get --field username "$NAME"|sed 's/Username: //') + if [ -n "$USERNAME" ]; then + wl-copy -n "$USERNAME" + printf '%s\n' "\"$NAME\" username copied to clipboard, press enter if you also want the password" + read ans + get_password + else + printf '%s\n' "\"$NAME\" doesn't have a username, copying password instead" + get_password + fi + } + + get_password () { + # Copy password to clipboard + rbw get --clipboard "$NAME" + printf '%s\n' "\"$NAME\" password copied to clipboard" + + # Wait 10 seconds before clearing the clipboard, you can raise or decrease the wait time by changing the WTIME variable value + WTIME=10 + while [ $WTIME -gt 0 ]; do + if [ $WTIME -gt 1 ]; then + printf '%s\n' "Clearing password from clipboard in $WTIME seconds" + else + printf '%s\n' "Clearing password from clipboard in $WTIME second" + fi + sleep 1 + WTIME=$((WTIME-1)) + done + + # Clear password from clipboard + wl-copy -c + + get_notes + } + + get_notes () { + NOTE=$(rbw get --field notes "$NAME") + if [ -n "$NOTE" ]; then + printf '%s\n\n' "\"$NAME\" notes:" + printf '%s\n\n' "$NOTE" + printf '%s\n' "Press enter to exit." + read ans + exit 0 + fi + } + + # Check if fzf, rbw and wl-copy exists in $PATH + for binary in rbw fzf wl-copy; do + command -v $binary 2>/dev/null 1>&2 || \ + { printf '%s\n' "$binary not found in \$PATH, make sure to install it before running this script" ; exit 1 ;} + done + + # Unlock the vault before running the script + if [ ! rbw unlocked 2>/dev/null 1>&2 ]; then + rbw unlock + fi + + get_entry +'' + diff --git a/pkgs/wl-clipedit/default.nix b/pkgs/wl-clipedit/default.nix index f6150b8..310c266 100644 --- a/pkgs/wl-clipedit/default.nix +++ b/pkgs/wl-clipedit/default.nix @@ -3,7 +3,6 @@ , wl-clipboard , coreutils , editor ? "hx" -, terminal-command ? "kitty -e" , }: # 64 │ function clipcopy() { xclip -in -selection clipboard < "${1:-/dev/stdin}"; } @@ -17,7 +16,7 @@ writeShellScriptBin "wl-clipedit" '' }" tmp_file=$(mktemp) wl-paste -t 'text/plain;charset=utf-8' -n > "$tmp_file" - ${terminal-command} ''${VISUAL:-''${EDITOR:-${editor}}} "$tmp_file" + ''${VISUAL:-''${EDITOR:-${editor}}} "$tmp_file" wl-copy -t 'text/plain;charset=utf-8' -n < "$tmp_file" rm "$tmp_file" ''