Merge pull request #1346 from matthiasbeyer/libimagrt/editor-in-config
libimagrt: editor in config
This commit is contained in:
commit
c5154e8363
3 changed files with 26 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue