From 52cd14086afbfae2a0ad26254c69508badbfbd67 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 20 Apr 2024 14:58:42 -0400 Subject: add --clipboard to rbw code --- src/bin/rbw/commands.rs | 3 ++- src/bin/rbw/main.rs | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/bin/rbw/commands.rs b/src/bin/rbw/commands.rs index 02ab63c..703a351 100644 --- a/src/bin/rbw/commands.rs +++ b/src/bin/rbw/commands.rs @@ -1025,6 +1025,7 @@ pub fn code( name: &str, user: Option<&str>, folder: Option<&str>, + clipboard: bool, ) -> anyhow::Result<()> { unlock()?; @@ -1042,7 +1043,7 @@ pub fn code( if let DecryptedData::Login { totp, .. } = decrypted.data { if let Some(totp) = totp { - println!("{}", generate_totp(&totp)?); + val_display_or_store(clipboard, &generate_totp(&totp)?); } else { return Err(anyhow::anyhow!( "entry does not contain a totp secret" diff --git a/src/bin/rbw/main.rs b/src/bin/rbw/main.rs index c0f623e..05dfa2b 100644 --- a/src/bin/rbw/main.rs +++ b/src/bin/rbw/main.rs @@ -95,6 +95,8 @@ enum Opt { user: Option, #[arg(long, help = "Folder name to search in")] folder: Option, + #[structopt(long, help = "Copy result to clipboard")] + clipboard: bool, }, #[command( @@ -334,9 +336,17 @@ fn main() { *raw, *clipboard, ), - Opt::Code { name, user, folder } => { - commands::code(name, user.as_deref(), folder.as_deref()) - } + Opt::Code { + name, + user, + folder, + clipboard, + } => commands::code( + name, + user.as_deref(), + folder.as_deref(), + *clipboard, + ), Opt::Add { name, user, -- cgit v1.2.3-54-g00ecf