From 5dc0bd9db2872292f5f6576f9ea6a6d5c406fd10 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 12 Mar 2018 23:18:33 +0100 Subject: [PATCH 1/5] Provide editor in config --- imagrc.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/imagrc.toml b/imagrc.toml index 7a834b1c..03cdec1e 100644 --- a/imagrc.toml +++ b/imagrc.toml @@ -1,6 +1,9 @@ # This is a example configuration file for the imag suite. # It is written in TOML +[rt] +editor = "vim" + # # imag supports templates when specifying formats. The templates support several # functionalities, from colorizing to underlining and such things. From b8c3f7f8346df790caec4d55303bfc65fe58b67b Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 12 Mar 2018 23:20:13 +0100 Subject: [PATCH 2/5] Read editor from configuration, ignore errors --- lib/core/libimagrt/src/runtime.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/core/libimagrt/src/runtime.rs b/lib/core/libimagrt/src/runtime.rs index 8bc1cf70..7fe0a959 100644 --- a/lib/core/libimagrt/src/runtime.rs +++ b/lib/core/libimagrt/src/runtime.rs @@ -25,6 +25,7 @@ use std::io::Stdin; pub use clap::App; use toml::Value; +use toml_query::read::TomlValueReadExt; use clap::{Arg, ArgMatches}; @@ -457,7 +458,15 @@ impl<'a> Runtime<'a> { self.cli() .value_of("editor") .map(String::from) + .or_else(|| { + self.config() + .and_then(|v| match v.read("rt.editor") { + Ok(Some(&Value::String(ref s))) => Some(s.clone()), + _ => None, // FIXME silently ignore errors in config is bad + }) + }) .or(env::var("EDITOR").ok()) + .map(|s| {debug!("Editing with '{}'", s); s}) .map(|s| { let mut c = Command::new(s); c.stdin(::std::process::Stdio::inherit()); From a23afa77721e15023bc2edb7d24ff94bd15a22e4 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 12 Mar 2018 23:20:32 +0100 Subject: [PATCH 3/5] Ensure command and args are provided correctly --- lib/core/libimagrt/src/runtime.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/core/libimagrt/src/runtime.rs b/lib/core/libimagrt/src/runtime.rs index 7fe0a959..1e29f96d 100644 --- a/lib/core/libimagrt/src/runtime.rs +++ b/lib/core/libimagrt/src/runtime.rs @@ -467,11 +467,17 @@ impl<'a> Runtime<'a> { }) .or(env::var("EDITOR").ok()) .map(|s| {debug!("Editing with '{}'", s); s}) - .map(|s| { - let mut c = Command::new(s); - c.stdin(::std::process::Stdio::inherit()); + .and_then(|s| { + let mut split = s.split(" "); + let command = split.next(); + if command.is_none() { + return None + } + let mut c = Command::new(command.unwrap()); // secured above + c.args(split); + c.stdin(::std::process::Stdio::null()); c.stderr(::std::process::Stdio::inherit()); - c + Some(c) }) } From ea2f9072ed06d7cebce6a1d0bc539dbf90b488c8 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 12 Mar 2018 23:23:37 +0100 Subject: [PATCH 4/5] Add changelog entry for rt.editor parsing in libimagrt --- doc/src/09020-changelog.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/src/09020-changelog.md b/doc/src/09020-changelog.md index 2c201df0..fd89a359 100644 --- a/doc/src/09020-changelog.md +++ b/doc/src/09020-changelog.md @@ -57,6 +57,8 @@ This section contains the changelog from the last release to the next release. * `imag-diary` supports "daily" diaries now. * `imag-contact` joins multiple emails with "," now * `imag-tag` commandline was rewritten for positional arguments. + * `libimagrt` automatically takes "rt.editor" into account when building + editor object * Bugfixes * imag does not panic anymore when piping and breaking that pipe, for example like with `imag store ids | head -n 1`. From 5549ee2f6e914fb67f1d6d3d78533d51cd155acc Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 12 Mar 2018 23:23:03 +0100 Subject: [PATCH 5/5] Add changelog entry for command-argument fix --- doc/src/09020-changelog.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/src/09020-changelog.md b/doc/src/09020-changelog.md index fd89a359..42c6da17 100644 --- a/doc/src/09020-changelog.md +++ b/doc/src/09020-changelog.md @@ -80,6 +80,8 @@ This section contains the changelog from the last release to the next release. `std::str::Lines` iterator takes empty lines as no lines. * `libimagentryedit` fixed to inherit stdin and stderr to child process for editor command. + * `libimagrt` produced the editor command without taking arguments into + account. ## 0.6.3