zellij/zellij-server/src/tab/copy_command.rs
Thomas Linford 18709acde9
feat(copy): allow osc52 copy destination configuration (#1022)
add copy_cliboard  option to allow configuring copy destination to primary selection instead of default clipboard
2022-02-02 15:22:34 +01:00

34 lines
974 B
Rust

use std::io::prelude::*;
use std::process::{Command, Stdio};
use zellij_utils::anyhow::{Context, Result};
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) -> Result<()> {
let process = Command::new(self.command.clone())
.args(self.args.clone())
.stdin(Stdio::piped())
.spawn()
.with_context(|| format!("couldn't spawn {}", self.command))?;
process
.stdin
.context("could not get stdin")?
.write_all(value.as_bytes())
.with_context(|| format!("couldn't write to {} stdin", self.command))?;
Ok(())
}
}