search by header
This commit is contained in:
parent
0a1d29d743
commit
44024f4743
@ -61,7 +61,7 @@ fn is_duplicate(header: &str, category: &str) -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Finds a path to desired note.
|
/// Finds a path to desired note.
|
||||||
fn find_path(header: &str) -> Result<String> {
|
pub fn find_path(header: &str) -> Result<String> {
|
||||||
let mut paths: Vec<String> = Vec::new();
|
let mut paths: Vec<String> = Vec::new();
|
||||||
let base = get_base_path()?;
|
let base = get_base_path()?;
|
||||||
let header = format!("{}.md", header);
|
let header = format!("{}.md", header);
|
||||||
@ -113,7 +113,7 @@ pub fn remove(header: &str) -> Result<()> {
|
|||||||
|
|
||||||
/// Modify a note.
|
/// Modify a note.
|
||||||
pub fn modify(header: &str) -> Result<()> {
|
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)?;
|
let file = find_path(header)?;
|
||||||
Command::new(editor).arg(&file).status()?;
|
Command::new(editor).arg(&file).status()?;
|
||||||
println!("Edited successfully!");
|
println!("Edited successfully!");
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::rnote::notes;
|
use crate::rnote::notes;
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use clap::ArgMatches;
|
use clap::ArgMatches;
|
||||||
use dialoguer::{theme::ColorfulTheme, Input};
|
use dialoguer::{theme::ColorfulTheme, Confirm, Input};
|
||||||
|
|
||||||
pub fn new(matches: &ArgMatches) -> Result<()> {
|
pub fn new(matches: &ArgMatches) -> Result<()> {
|
||||||
let header = match matches.value_of("header") {
|
let header = match matches.value_of("header") {
|
||||||
@ -41,7 +41,19 @@ pub fn list(matches: &ArgMatches) -> Result<()> {
|
|||||||
}
|
}
|
||||||
pub fn search(matches: &ArgMatches) -> Result<()> {
|
pub fn search(matches: &ArgMatches) -> Result<()> {
|
||||||
match matches.value_of("header") {
|
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") {
|
None => match matches.is_present("word") {
|
||||||
true => {
|
true => {
|
||||||
let s: String = Input::with_theme(&ColorfulTheme::default())
|
let s: String = Input::with_theme(&ColorfulTheme::default())
|
||||||
|
Loading…
Reference in New Issue
Block a user