diff --git a/README.adoc b/README.adoc index cd4cdcb..b4e5675 100644 --- a/README.adoc +++ b/README.adoc @@ -47,7 +47,8 @@ define-command sort-selections -params 0.. %{ # TODO: Send additional parameters - rust-selection-sort -R "$regex" $args -- "$@" > "$kak_command_fifo" + rust-selection-sort -R "$regex" -f "$kak_command_fifo" -- "$@" + } exec R } diff --git a/src/main.rs b/src/main.rs index 787fd31..bd6c7bf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,8 @@ use alphanumeric_sort::compare_str; use clap::Parser; use regex::Regex; +use std::fs::OpenOptions; +use std::io::Write; use std::path::PathBuf; struct KakMessage(String, Option); @@ -91,7 +93,12 @@ fn run() -> Result<(), KakMessage> { } }); - print!("reg '\"'"); + let mut f = OpenOptions::new() + .write(true) + .append(true) + .open(&options.fifo_name)?; + + write!(f, "reg '\"'")?; let iter: Box> = if options.reverse { Box::new(zipped.iter().rev()) @@ -101,9 +108,9 @@ fn run() -> Result<(), KakMessage> { for i in iter { let new_selection = i.0.replace('\'', "''"); - print!(" '{}'", new_selection); + write!(f, " '{}'", new_selection)?; } - print!(" ;"); + write!(f, " ;")?; Ok(()) }