diff options
| author | Christophe Verbinnen <christophe@verbinnen.org> | 2022-01-15 06:38:45 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-15 12:38:45 +0100 |
| commit | 9cc2645db024df0a95efda42aed34bd3def19b28 (patch) | |
| tree | d2345ca39dba0d5a2bf2cd7527799859147d6d69 /zellij-server/src/tab/copy_command.rs | |
| parent | docs(changelog): fix dependency problem (diff) | |
| download | sl0ppij-9cc2645db024df0a95efda42aed34bd3def19b28.tar.gz sl0ppij-9cc2645db024df0a95efda42aed34bd3def19b28.tar.xz sl0ppij-9cc2645db024df0a95efda42aed34bd3def19b28.zip | |
Add a copy command option (#996)
Usage: zellij options --copy-command "xclip -sel clip"
Co-authored-by: Christophe Verbinnen <christophev@knowbe4.com>
Diffstat (limited to 'zellij-server/src/tab/copy_command.rs')
| -rw-r--r-- | zellij-server/src/tab/copy_command.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/zellij-server/src/tab/copy_command.rs b/zellij-server/src/tab/copy_command.rs new file mode 100644 index 00000000..61240950 --- /dev/null +++ b/zellij-server/src/tab/copy_command.rs @@ -0,0 +1,39 @@ +use std::io::prelude::*; +use std::process::{Command, Stdio}; + +pub struct CopyCommand { + command: String, + args: Vec<String>, +} + +impl CopyCommand { + pub fn new(command: String) -> Self { + let mut command_with_args = command.split(' ').map(String::from); + + Self { + command: command_with_args.next().expect("missing command"), + args: command_with_args.collect(), + } + } + pub fn set(&self, value: String) -> bool { + let process = match Command::new(self.command.clone()) + .args(self.args.clone()) + .stdin(Stdio::piped()) + .spawn() + { + Err(why) => { + eprintln!("couldn't spawn {}: {}", self.command, why); + return false; + } + Ok(process) => process, + }; + + match process.stdin.unwrap().write_all(value.as_bytes()) { + Err(why) => { + eprintln!("couldn't write to {} stdin: {}", self.command, why); + false + } + Ok(_) => true, + } + } +} |
