launching editor for current file
This commit is contained in:
parent
175a6c20a8
commit
9c96744bda
21
src/main.rs
21
src/main.rs
|
|
@ -3,6 +3,7 @@ use chrono::{Datelike, Local};
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::process::Command;
|
||||||
use todo_file::TodoFile;
|
use todo_file::TodoFile;
|
||||||
|
|
||||||
//TODO handle unwraps and errors more uniformly
|
//TODO handle unwraps and errors more uniformly
|
||||||
|
|
@ -12,19 +13,19 @@ fn main() {
|
||||||
let data_dir = get_data_dir("notes");
|
let data_dir = get_data_dir("notes");
|
||||||
|
|
||||||
println!("{}", data_dir.to_str().unwrap());
|
println!("{}", data_dir.to_str().unwrap());
|
||||||
let latest_file = get_latest_file(&data_dir).unwrap();
|
let latest_file =
|
||||||
//.expect(
|
get_latest_file(&data_dir).expect(format!("Could not find any notes files").as_str());
|
||||||
// format!(
|
|
||||||
// "Could not find any notes files please use format: {}",
|
|
||||||
// get_file_regex().to_string()
|
|
||||||
// )
|
|
||||||
// .as_str(),
|
|
||||||
//);
|
|
||||||
println!("Latest file: {:?}", latest_file);
|
println!("Latest file: {:?}", latest_file);
|
||||||
let now = Local::now();
|
let now = Local::now();
|
||||||
let today = NaiveDate::from_ymd_opt(now.year(), now.month(), now.day());
|
let today = NaiveDate::from_ymd_opt(now.year(), now.month(), now.day());
|
||||||
match today {
|
match today {
|
||||||
Some(today) if latest_file.date == today => println!("Todays file was created"),
|
Some(today) if latest_file.date == today => {
|
||||||
|
println!("Todays file was created");
|
||||||
|
Command::new("vim")
|
||||||
|
.args([latest_file.file.path()])
|
||||||
|
.status()
|
||||||
|
.expect(format!("failed to launch editor {}", "vim").as_str());
|
||||||
|
}
|
||||||
Some(today) if latest_file.date < today => println!("Todays file was not created"),
|
Some(today) if latest_file.date < today => println!("Todays file was not created"),
|
||||||
Some(today) if latest_file.date > today => println!("Future files were created"),
|
Some(today) if latest_file.date > today => println!("Future files were created"),
|
||||||
|
|
||||||
|
|
@ -34,10 +35,10 @@ fn main() {
|
||||||
|
|
||||||
mod todo_file {
|
mod todo_file {
|
||||||
use chrono::naive::NaiveDate;
|
use chrono::naive::NaiveDate;
|
||||||
|
use regex::Regex;
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
use std::fs::DirEntry;
|
use std::fs::DirEntry;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use regex::Regex;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct TodoFile {
|
pub struct TodoFile {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue