mirror of
https://github.com/icewind1991/zox
synced 2026-06-03 18:34:07 +02:00
handle missing .z
This commit is contained in:
parent
a59f4db38e
commit
73c7464c26
1 changed files with 24 additions and 24 deletions
14
src/main.rs
14
src/main.rs
|
|
@ -91,22 +91,20 @@ fn main() -> Result<(), MainError> {
|
|||
let home = home::home_dir().expect("Cant get home directory");
|
||||
let history_path = home.join(".z");
|
||||
|
||||
let mut reader = csv::ReaderBuilder::new()
|
||||
let history_result = csv::ReaderBuilder::new()
|
||||
.delimiter(b'|')
|
||||
.has_headers(false)
|
||||
.from_path(history_path.clone())
|
||||
.unwrap();
|
||||
.map(|reader| reader.into_deserialize::<History>().filter_map(Result::ok));
|
||||
|
||||
let now = now();
|
||||
|
||||
let history = reader
|
||||
.deserialize::<History>()
|
||||
.filter_map(|result| result.ok());
|
||||
|
||||
if args.add {
|
||||
let home = home.to_str().expect("Home path not valid utf8").to_string();
|
||||
|
||||
let mut history: Vec<_> = history.collect();
|
||||
let mut history: Vec<_> = history_result
|
||||
.map(|history| history.collect())
|
||||
.unwrap_or_default();
|
||||
|
||||
for path in args.filter {
|
||||
if path != home {
|
||||
|
|
@ -152,6 +150,7 @@ fn main() -> Result<(), MainError> {
|
|||
return Ok(());
|
||||
}
|
||||
|
||||
if let Ok(history) = history_result {
|
||||
let matches = history.filter(|item| item.matches(&args.filter));
|
||||
|
||||
if args.list {
|
||||
|
|
@ -172,6 +171,7 @@ fn main() -> Result<(), MainError> {
|
|||
println!("{}", first.path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue