Merge branch 'test' into 'main'
search by header See merge request paris8-rust/rnote!4
This commit is contained in:
commit
8210cb37aa
@ -61,7 +61,7 @@ fn is_duplicate(header: &str, category: &str) -> Result<()> {
|
||||
}
|
||||
|
||||
/// 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 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!");
|
||||
|
@ -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())
|
||||
|
Loading…
Reference in New Issue
Block a user