Skip to content
This repository has been archived by the owner on Apr 5, 2021. It is now read-only.

Commit

Permalink
Handle clipboard copy on Linux
Browse files Browse the repository at this point in the history
This is related to an issue with the clipboard handling in xorg,
see aweinstock314/rust-clipboard#61

This now forks a child process and sleeps for 10 seconds, after
which it clears the clipboard before exiting.

Closes #5
  • Loading branch information
stchris committed Jun 27, 2020
1 parent 2666a94 commit aa27b67
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added
- Short option `-o` for `passage show --on-screen`
- Fix clipboard copying on Linux. A child process is spawned and keeps the content on the clipboard for 10 seconds. See #5
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ rpassword = "4.0"
structopt = {version="0.3", features=["color"]}
lazy_static = "1.4"
clipboard = "0.5"
fork = "0.1.15"
17 changes: 13 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use lazy_static::lazy_static;
use anyhow::Error;
use clipboard::ClipboardContext;
use clipboard::ClipboardProvider;
use fork::{fork, Fork};
use secrecy::Secret;
use structopt::StructOpt;

Expand Down Expand Up @@ -113,10 +114,18 @@ fn show(entry: &str, on_screen: bool) -> Result<(), Error> {
let decrypted = String::from_utf8(decrypted)?;
match on_screen {
true => println!("{}", decrypted),
false => {
let mut ctx: ClipboardContext = ClipboardProvider::new().unwrap();
ctx.set_contents(decrypted.to_owned()).unwrap();
}
false => match fork() {
Ok(Fork::Child) => {
let mut ctx: ClipboardContext = ClipboardProvider::new().unwrap();
ctx.set_contents(decrypted.to_owned()).unwrap();

std::thread::sleep(std::time::Duration::from_secs(10));

ctx.set_contents("".to_owned()).unwrap();
}
Err(_) => return Err(Error::msg("Failed to fork()")),
_ => {}
},
}

Ok(())
Expand Down

0 comments on commit aa27b67

Please sign in to comment.