summaryrefslogtreecommitdiffstats
path: root/src/edit.rs
blob: e7f0afbac28b56b2f02bcffd14c81a4f0963028d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use std::env;
use std::fs;
use std::process::Command;

use utils::dateutil;

pub fn do_edit(filenames: &mut Iterator<Item = String>, _args: &[String]) {

  let mut paths: Vec<String> = filenames.map( |line| {
    let parts: Vec<&str> = line.splitn(2, ' ').collect();
    match dateutil::datetime_from_timestamp(parts[0]) {
      Some(_) => parts[1].to_string(),
      None => parts[0].to_string(),
    }
  }).collect();
  paths.sort_unstable();
  paths.dedup();

  let editor = env::var("EDITOR").unwrap_or_else(|_| "vim".to_string());

  if let Err(error) = Command::new(&editor)
    .args(paths)
    .stdin(fs::File::open("/dev/tty").unwrap())
    .status() {
      error!("{} command failed to start, error: {}", editor, error);
      return
    };
}