Better wl-clipedit and rbw-fzf

This commit is contained in:
Filippo Berto 2026-02-05 09:41:18 +01:00
parent ca4e245fd0
commit 1deb75a769
No known key found for this signature in database
GPG key ID: F1D17F9BCEC62FBC
6 changed files with 95 additions and 3 deletions

View file

@ -118,6 +118,7 @@
inherit inherit
(pkgs) (pkgs)
keyboard-switch keyboard-switch
rbw-fzf
wl-clipedit wl-clipedit
wl-lockscreen wl-lockscreen
wl-update-background wl-update-background
@ -178,6 +179,7 @@
packages = self: _super: { packages = self: _super: {
keyboard-switch = self.callPackage ./pkgs/keyboard-switch { }; keyboard-switch = self.callPackage ./pkgs/keyboard-switch { };
wl-clipedit = self.callPackage ./pkgs/wl-clipedit { }; wl-clipedit = self.callPackage ./pkgs/wl-clipedit { };
rbw-fzf = self.callPackage ./pkgs/rbw-fzf { };
wl-lockscreen = self.callPackage ./pkgs/wl-lockscreen { }; wl-lockscreen = self.callPackage ./pkgs/wl-lockscreen { };
wl-update-background = self.callPackage ./pkgs/wl-update-background { }; wl-update-background = self.callPackage ./pkgs/wl-update-background { };
}; };

View file

@ -29,6 +29,7 @@ in
hyprpaper hyprpaper
networkmanagerapplet networkmanagerapplet
playerctl playerctl
rbw-fzf
sirula sirula
# swaylock # swaylock
swww swww
@ -228,7 +229,8 @@ in
"SUPER, P, pseudo, # dwindle" "SUPER, P, pseudo, # dwindle"
"SUPER, J, togglesplit, # dwindle" "SUPER, J, togglesplit, # dwindle"
"SUPER ALT, E, exec, wofi-emoji" "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" "SUPER ALT, B, exec, systemctl --user reload-or-restart wl-update-background"
",Print, exec, grimblast copy" ",Print, exec, grimblast copy"
"SHIFT, Print, exec, grimblast copy area" "SHIFT, Print, exec, grimblast copy area"

View file

@ -46,6 +46,7 @@
pavucontrol pavucontrol
procps procps
protonvpn-gui protonvpn-gui
rbw
# spotify # spotify
telegram-desktop telegram-desktop
wiremix wiremix

View file

@ -50,6 +50,7 @@
pavucontrol pavucontrol
procps procps
protonvpn-gui protonvpn-gui
rbw
# spotify # spotify
telegram-desktop telegram-desktop
thunderbird thunderbird

87
pkgs/rbw-fzf/default.nix Normal file
View file

@ -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
''

View file

@ -3,7 +3,6 @@
, wl-clipboard , wl-clipboard
, coreutils , coreutils
, editor ? "hx" , editor ? "hx"
, terminal-command ? "kitty -e"
, ,
}: }:
# 64 │ function clipcopy() { xclip -in -selection clipboard < "${1:-/dev/stdin}"; } # 64 │ function clipcopy() { xclip -in -selection clipboard < "${1:-/dev/stdin}"; }
@ -17,7 +16,7 @@ writeShellScriptBin "wl-clipedit" ''
}" }"
tmp_file=$(mktemp) tmp_file=$(mktemp)
wl-paste -t 'text/plain;charset=utf-8' -n > "$tmp_file" 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" wl-copy -t 'text/plain;charset=utf-8' -n < "$tmp_file"
rm "$tmp_file" rm "$tmp_file"
'' ''