Skip to content

Commit

Permalink
Merge pull request #462 from euank/tmp/pr-updates
Browse files Browse the repository at this point in the history
cargo update a buncha stuff, update editions
  • Loading branch information
euank committed Feb 21, 2024
2 parents 15808e3 + e1c14a2 commit 6bbfe29
Show file tree
Hide file tree
Showing 12 changed files with 478 additions and 462 deletions.
203 changes: 130 additions & 73 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repository = "https://github.com/euank/pazi"
readme = "README.md"
keywords = ["autojump", "shell", "productivity-tool"]
license = "GPL-3.0"
edition = "2018"
edition = "2021"

[dependencies.clap]
version = "~2"
Expand Down
1 change: 0 additions & 1 deletion bors.toml

This file was deleted.

2 changes: 1 addition & 1 deletion src/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn edit(data: &[(String, f64)]) -> Result<PathFrecencyDiff> {
.or_else(|_| {
for bin in &["editor", "nano", "vim", "vi"] {
if let Ok(ed) = which::which(bin) {
return Ok((ed, vec![]));
return Ok((ed, vec![]));
}
}
Err(anyhow!("could not find editor in path"))
Expand Down
16 changes: 3 additions & 13 deletions src/frecency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@ where
}
};
}
match min_entry {
None => None,
Some(e) => Some(e.0.clone()),
}
min_entry.map(|e| e.0.clone())
};

if let Some(min) = min_key {
Expand All @@ -130,11 +127,7 @@ where
I: IntoIterator<Item = (&'a T, &'a f64)>,
{
pub fn normalized(self) -> Vec<(&'a T, f64)> {
let mut items: Vec<_> = self
.items
.into_iter()
.map(|(k, v)| (k, *v))
.collect();
let mut items: Vec<_> = self.items.into_iter().map(|(k, v)| (k, *v)).collect();
if items.is_empty() {
return Vec::new();
}
Expand All @@ -155,10 +148,7 @@ where
}

pub fn raw(self) -> Vec<(&'a T, f64)> {
self.items
.into_iter()
.map(|(k, v)| (k, *v))
.collect()
self.items.into_iter().map(|(k, v)| (k, *v)).collect()
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/frecent_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ impl PathFrecency {
};
let matched = items.iter().flat_map(|item| {
matchers.iter().filter_map(move |m| {
m.matches(&item.0, filter)
.map(move |v| weight(&item.0, item.1, v))
m.matches(item.0, filter)
.map(move |v| weight(item.0, item.1, v))
})
});

Expand Down
7 changes: 3 additions & 4 deletions src/importers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::io::BufRead;
use std::io::BufReader;
use std::path::{Path, PathBuf};

use log::{warn, debug};
use log::{debug, warn};

pub struct Fasd;

Expand All @@ -22,8 +22,7 @@ impl Fasd {
// For proper compatibility, this should use 'shellexpand' or a similar crate.
Ok(dir) => PathBuf::from(dir),
Err(_) => {
let user_dirs =
directories::UserDirs::new().ok_or("could not get home dir")?;
let user_dirs = directories::UserDirs::new().ok_or("could not get home dir")?;
let home = user_dirs.home_dir();
home.join(".fasd")
}
Expand All @@ -39,7 +38,7 @@ impl Fasd {

for line in BufReader::new(f).lines() {
let line = line.map_err(|e| format!("error reading {:?}: {}", &fasd_data, e))?;
let data = match line.splitn(2, '|').next() {
let data = match line.split('|').next() {
None => {
warn!("Incorrectly formatted fasd data line: {}", line);
continue;
Expand Down
24 changes: 8 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ fn _main() -> PaziResult {
} else {
res = PaziResult::Error;
}
} else if flags.value_of("dir_target") != None {
} else if flags.value_of("dir_target").is_some() {
// Something got interpreted as 'dir_target' even though this wasn't in '--dir'
println!("pazi: could not parse given flags.\n\n{}", flags.usage());
return PaziResult::Error;
Expand Down Expand Up @@ -386,17 +386,12 @@ fn handle_edit(cmd: &ArgMatches) -> PaziResult {
return PaziResult::Error;
}
};
match frecency.apply_diff(diff) {
Err(e) => {
println!("Error applying edit diff: {:?}", e);
return PaziResult::Error;
}
Ok(()) => {}
if let Err(e) = frecency.apply_diff(diff) {
println!("Error applying edit diff: {:?}", e);
return PaziResult::Error;
};
match frecency.save_to_disk() {
Ok(_) => {
PaziResult::Success
}
Ok(_) => PaziResult::Success,
Err(e) => {
println!("pazi: error saving db: {:?}", e);
PaziResult::Error
Expand Down Expand Up @@ -473,7 +468,6 @@ fn handle_jump(cmd: &ArgMatches) -> PaziResult {
return PaziResult::Error;
}
};
let res;

let mut matches = match cmd.value_of("dir_target") {
Some(to) => {
Expand All @@ -487,7 +481,7 @@ fn handle_jump(cmd: &ArgMatches) -> PaziResult {
None => frecency.items_with_frecency(),
};

res = if cmd.is_present("interactive") {
let res = if cmd.is_present("interactive") {
let stdout = termion::get_tty().unwrap();
match interactive::filter(matches, std::io::stdin(), stdout) {
Ok(el) => {
Expand Down Expand Up @@ -551,9 +545,7 @@ fn handle_visit(cmd: &ArgMatches) -> PaziResult {
frecency.visit(dir.to_string());

match frecency.save_to_disk() {
Ok(_) => {
PaziResult::Success
}
Ok(_) => PaziResult::Success,
Err(e) => {
println!("pazi: error adding directory: {:?}", e);
PaziResult::Error
Expand Down Expand Up @@ -597,7 +589,7 @@ fn frecency_path() -> Result<PathBuf, String> {
.ok_or_else(|| "unable to determine config path".to_string())?;
let config_dir = project_dir.config_dir();

std::fs::create_dir_all(&config_dir)
std::fs::create_dir_all(config_dir)
.map_err(|e| format!("could not create config dir: {}", e))?;

let db_path = config_dir.join(PAZI_DB_NAME);
Expand Down
13 changes: 6 additions & 7 deletions src/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,12 @@ impl<'a> CaseInsensitiveMatcher<'a> {

impl<'a> Matcher for TransformedMatcher<'a> {
fn matches(&self, input: &str, search: &str) -> Option<f64> {
match self.matcher.matches(
&(self.input_transformation)(input),
&(self.search_transformation)(search),
) {
Some(f) => Some(f * self.attenuation),
None => None,
}
self.matcher
.matches(
&(self.input_transformation)(input),
&(self.search_transformation)(search),
)
.map(|f| f * self.attenuation)
}
}

Expand Down
Loading

0 comments on commit 6bbfe29

Please sign in to comment.