diff --git a/.config/niri/scripts/rbw-fish.fish b/.config/niri/scripts/rbw-fish.fish index dc9e3820..27150b3d 100755 --- a/.config/niri/scripts/rbw-fish.fish +++ b/.config/niri/scripts/rbw-fish.fish @@ -1,6 +1,19 @@ #!/usr/bin/env fish - -set -l query (echo username\npassword\ncode | fuzzel --prompt="> " --dmenu) +set -l action +if test (count $argv) -ne 0 + set action $argv[1] +else + set action (echo copy\ntype\nshow | fuzzel --prompt="Action> " --dmenu) +end +set -l query +set -l queries username password code +if test "$action" = type + set --append queries double +end +set query (string join \n $queries | fuzzel --prompt="Query> " --dmenu) +if test -z "$query" + return 1 +end set -l selected (rbw list | fuzzel --prompt="$query: " --dmenu) if test -z "$selected" @@ -10,8 +23,29 @@ end set -l output if test "$query" = code set output (rbw code "$selected") +else if test "$query" = double + for i in username password + set --append output (rbw get "$selected" --raw | jq --join-output ".data.$i") + end else set output (rbw get "$selected" --raw | jq --join-output ".data.$query") end +switch $action + case copy + wl-copy $output + case type + if test (count $output) -eq 1 + wtype "$output" + else + wtype "$output[1]" + wtype -k Tab + wtype "$output[2]" + end + case show + notify-send --wait "$output" + case '*' + notify-send "Invalid command!" +end + wl-copy $output