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
46
src/main.rs
46
src/main.rs
|
|
@ -91,22 +91,20 @@ fn main() -> Result<(), MainError> {
|
||||||
let home = home::home_dir().expect("Cant get home directory");
|
let home = home::home_dir().expect("Cant get home directory");
|
||||||
let history_path = home.join(".z");
|
let history_path = home.join(".z");
|
||||||
|
|
||||||
let mut reader = csv::ReaderBuilder::new()
|
let history_result = csv::ReaderBuilder::new()
|
||||||
.delimiter(b'|')
|
.delimiter(b'|')
|
||||||
.has_headers(false)
|
.has_headers(false)
|
||||||
.from_path(history_path.clone())
|
.from_path(history_path.clone())
|
||||||
.unwrap();
|
.map(|reader| reader.into_deserialize::<History>().filter_map(Result::ok));
|
||||||
|
|
||||||
let now = now();
|
let now = now();
|
||||||
|
|
||||||
let history = reader
|
|
||||||
.deserialize::<History>()
|
|
||||||
.filter_map(|result| result.ok());
|
|
||||||
|
|
||||||
if args.add {
|
if args.add {
|
||||||
let home = home.to_str().expect("Home path not valid utf8").to_string();
|
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 {
|
for path in args.filter {
|
||||||
if path != home {
|
if path != home {
|
||||||
|
|
@ -152,24 +150,26 @@ fn main() -> Result<(), MainError> {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let matches = history.filter(|item| item.matches(&args.filter));
|
if let Ok(history) = history_result {
|
||||||
|
let matches = history.filter(|item| item.matches(&args.filter));
|
||||||
|
|
||||||
if args.list {
|
if args.list {
|
||||||
for item in matches {
|
for item in matches {
|
||||||
println!("{:<11}{}", item.get_sort(args.sort, now), item.path);
|
println!("{:<11}{}", item.get_sort(args.sort, now), item.path);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let mut matches: Vec<History> = matches.collect();
|
let mut matches: Vec<History> = matches.collect();
|
||||||
matches.sort_by(
|
matches.sort_by(
|
||||||
|a, b| match a.get_sort(args.sort, now) - b.get_sort(args.sort, now) {
|
|a, b| match a.get_sort(args.sort, now) - b.get_sort(args.sort, now) {
|
||||||
diff if diff < 0.0 => Ordering::Greater,
|
diff if diff < 0.0 => Ordering::Greater,
|
||||||
diff if diff > 0.0 => Ordering::Less,
|
diff if diff > 0.0 => Ordering::Less,
|
||||||
_ => Ordering::Equal,
|
_ => Ordering::Equal,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Some(first) = matches.first() {
|
if let Some(first) = matches.first() {
|
||||||
println!("{}", first.path);
|
println!("{}", first.path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue