diff options
author | IIIIII <github@bigly.dog> | 2022-02-04 01:00:19 -0800 |
---|---|---|
committer | IIIIII <github@bigly.dog> | 2022-02-04 01:08:33 -0800 |
commit | 387d1581d6998a491f58d40af96c7d2c2f2a8f39 (patch) | |
tree | 085c91b7aa0897bb8d2190bf6c104218f238f203 | |
parent | c1ec75a6e9ab6685a597f5ad72c7230a67206ba7 (diff) |
ok
-rw-r--r-- | src/argparse.rs | 4 | ||||
-rw-r--r-- | src/fzf.rs | 34 | ||||
-rw-r--r-- | src/input.rs | 2 |
3 files changed, 23 insertions, 17 deletions
diff --git a/src/argparse.rs b/src/argparse.rs index 344db7a..16c7668 100644 --- a/src/argparse.rs +++ b/src/argparse.rs @@ -33,8 +33,8 @@ pub struct Arguments { pub replace: Option<String>, /// Use \0 as stdin delimiter - #[structopt(short = "0", long = "read0")] - pub nul_delim: bool, + #[structopt(short = "0")] + pub read0: bool, /// No preview, write changes to file #[structopt(short = "k", long)] @@ -1,4 +1,5 @@ use super::{ + argparse::Mode, subprocess::{stream_into, SubprocessCommand}, types::{Abort, Fail}, }; @@ -122,32 +123,37 @@ pub fn stream_fzf( args: Vec<String>, stream: Receiver<String>, ) -> JoinHandle<()> { - let sad = env::current_exe() - .or_else(|_| which("sad".to_owned())) - .map(|path| format!("{}", path.display())) - .unwrap_or_else(|_| "sad".to_owned()); - - let preview_args = env::args().skip(1).collect::<Vec<_>>().join("\x04"); - let execute = format!("abort+execute:{sad}\x04--internal-patch\x04{{+f}}\x04{preview_args}"); + let execute = format!("abort+execute:{}\x04{{+f}}", Mode::PATCH); let mut arguments = vec![ "--read0".to_owned(), "--print0".to_owned(), "-m".to_owned(), "--ansi".to_owned(), + "--preview-window=70%:wrap".to_owned(), format!("--bind=enter:{execute}"), format!("--bind=double-click:{execute}"), - format!("--preview={sad}\x04--internal-preview\x04{{f}}\x04{preview_args}",), - "--preview-window=70%:wrap".to_owned(), + format!("--preview={}\x04{{f}}", Mode::PREVIEW), ]; arguments.extend(args); - let mut env = HashMap::new(); - env.insert("SHELL".to_owned(), sad); - // WARN -- versions of FZF only work with C locale. - env.insert("LC_ALL".to_owned(), "C".to_owned()); + + let mut fzf_env = HashMap::new(); + fzf_env.insert( + Mode::ARGV.to_owned(), + env::args().skip(1).collect::<Vec<_>>().join("\0"), + ); + fzf_env.insert( + "SHELL".to_owned(), + env::current_exe() + .or_else(|_| which("sad".to_owned())) + .map(|path| format!("{}", path.display())) + .unwrap_or_else(|_| "sad".to_owned()), + ); + fzf_env.insert("LC_ALL".to_owned(), "C".to_owned()); + let cmd = SubprocessCommand { prog: bin, args: arguments, - env, + env: fzf_env, }; run_fzf(abort, cmd, stream) } diff --git a/src/input.rs b/src/input.rs index 8ea1807..1ed7abc 100644 --- a/src/input.rs +++ b/src/input.rs @@ -214,7 +214,7 @@ pub fn stream_input( args: &Arguments, ) -> (JoinHandle<()>, Receiver<Payload>) { match mode { - Mode::Initial => stream_stdin(abort, args.nul_delim), + Mode::Initial => stream_stdin(abort, args.read0), Mode::Preview(path) => stream_patch(abort, path), Mode::Patch(path) => stream_patch(abort, path), } |