summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-03-14 11:39:01 +0100
committerGitHub <noreply@github.com>2018-03-14 11:39:01 +0100
commitc5154e8363373d6f0f347097cee9cf47cf88fa45 (patch)
tree85a69f5bafd857a2224842263f88a2c72afa72e6
parentdc76729bea6bd7ff7e096ab629cf0f54f3c86f96 (diff)
parent5549ee2f6e914fb67f1d6d3d78533d51cd155acc (diff)
downloadimag-c5154e8363373d6f0f347097cee9cf47cf88fa45.zip
imag-c5154e8363373d6f0f347097cee9cf47cf88fa45.tar.gz
Merge pull request #1346 from matthiasbeyer/libimagrt/editor-in-config
libimagrt: editor in config
-rw-r--r--doc/src/09020-changelog.md4
-rw-r--r--imagrc.toml3
-rw-r--r--lib/core/libimagrt/src/runtime.rs23
3 files changed, 26 insertions, 4 deletions
diff --git a/doc/src/09020-changelog.md b/doc/src/09020-changelog.md
index 2c201df..42c6da1 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`.
@@ -78,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
diff --git a/imagrc.toml b/imagrc.toml
index 7a834b1..03cdec1 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.
diff --git a/lib/core/libimagrt/src/runtime.rs b/lib/core/libimagrt/src/runtime.rs
index 8bc1cf7..1e29f96 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,12 +458,26 @@ 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| {
- let mut c = Command::new(s);
- c.stdin(::std::process::Stdio::inherit());
+ .map(|s| {debug!("Editing with '{}'", s); s})
+ .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)
})
}