diff --git a/src/rnote/notes.rs b/src/rnote/notes.rs index e983822..af93f28 100644 --- a/src/rnote/notes.rs +++ b/src/rnote/notes.rs @@ -61,7 +61,7 @@ fn is_duplicate(header: &str, category: &str) -> Result<()> { } /// Finds a path to desired note. -fn find_path(header: &str) -> Result { +pub fn find_path(header: &str) -> Result { let mut paths: Vec = Vec::new(); let base = get_base_path()?; let header = format!("{}.md", header); @@ -113,7 +113,7 @@ pub fn remove(header: &str) -> Result<()> { /// Modify a note. pub fn modify(header: &str) -> Result<()> { - let editor = env::var("EDITOR").unwrap_or("/bin/vi".to_owned()); + let editor = env::var("EDITOR")?; let file = find_path(header)?; Command::new(editor).arg(&file).status()?; println!("Edited successfully!"); diff --git a/src/rnote/process.rs b/src/rnote/process.rs index fb831d5..32224e4 100644 --- a/src/rnote/process.rs +++ b/src/rnote/process.rs @@ -1,7 +1,7 @@ use crate::rnote::notes; use anyhow::{anyhow, Result}; use clap::ArgMatches; -use dialoguer::{theme::ColorfulTheme, Input}; +use dialoguer::{theme::ColorfulTheme, Confirm, Input}; pub fn new(matches: &ArgMatches) -> Result<()> { let header = match matches.value_of("header") { @@ -41,7 +41,19 @@ pub fn list(matches: &ArgMatches) -> Result<()> { } pub fn search(matches: &ArgMatches) -> Result<()> { match matches.value_of("header") { - Some(s) => unimplemented!("{}", s), + Some(s) => { + let p = notes::find_path(s)?; + if Confirm::with_theme(&ColorfulTheme::default()) + .with_prompt("Do you want to open it?") + .default(true) + .interact()? + { + let editor = std::env::var("EDITOR")?; + std::process::Command::new(editor).arg(&p).status()?; + } else { + println!("{}", p); + } + } None => match matches.is_present("word") { true => { let s: String = Input::with_theme(&ColorfulTheme::default())