diff --git a/build.rs b/build.rs index 36acf7c..90075d6 100644 --- a/build.rs +++ b/build.rs @@ -4,10 +4,10 @@ use std::{env, io}; fn main() { let pkg_version = env!("CARGO_PKG_VERSION"); let version = match env::var_os("PROFILE") { - Some(profile) if profile == "release" => format!("v{}", pkg_version), - _ => git_version().unwrap_or_else(|| format!("v{}-unknown", pkg_version)), + Some(profile) if profile == "release" => format!("v{pkg_version}"), + _ => git_version().unwrap_or_else(|| format!("v{pkg_version}-unknown")), }; - println!("cargo:rustc-env=ZOXIDE_VERSION={}", version); + println!("cargo:rustc-env=ZOXIDE_VERSION={version}"); // Since we are generating completions in the package directory, we need to set this so that // Cargo doesn't rebuild every time. diff --git a/src/cmd/add.rs b/src/cmd/add.rs index 0437b5a..f33d8db 100644 --- a/src/cmd/add.rs +++ b/src/cmd/add.rs @@ -27,7 +27,7 @@ impl Run for Add { continue; } if !Path::new(path).is_dir() { - bail!("not a directory: {}", path); + bail!("not a directory: {path}"); } db.add(path, now); } diff --git a/src/cmd/import.rs b/src/cmd/import.rs index e0557f5..b9e6299 100644 --- a/src/cmd/import.rs +++ b/src/cmd/import.rs @@ -33,13 +33,13 @@ fn from_autojump<'a>(db: &mut Database<'a>, buffer: &'a str) -> Result<()> { } let mut split = line.splitn(2, '\t'); - let rank = split.next().with_context(|| format!("invalid entry: {}", line))?; - let mut rank = rank.parse::().with_context(|| format!("invalid rank: {}", rank))?; + let rank = split.next().with_context(|| format!("invalid entry: {line}"))?; + let mut rank = rank.parse::().with_context(|| format!("invalid rank: {rank}"))?; // Normalize the rank using a sigmoid function. Don't import actual ranks from autojump, // since its scoring algorithm is very different and might take a while to get normalized. rank = sigmoid(rank); - let path = split.next().with_context(|| format!("invalid entry: {}", line))?; + let path = split.next().with_context(|| format!("invalid entry: {line}"))?; db.dirs.push(Dir { path: path.into(), rank, last_accessed: 0 }); db.modified = true; @@ -59,13 +59,13 @@ fn from_z<'a>(db: &mut Database<'a>, buffer: &'a str) -> Result<()> { } let mut split = line.rsplitn(3, '|'); - let last_accessed = split.next().with_context(|| format!("invalid entry: {}", line))?; - let last_accessed = last_accessed.parse().with_context(|| format!("invalid epoch: {}", last_accessed))?; + let last_accessed = split.next().with_context(|| format!("invalid entry: {line}"))?; + let last_accessed = last_accessed.parse().with_context(|| format!("invalid epoch: {last_accessed}"))?; - let rank = split.next().with_context(|| format!("invalid entry: {}", line))?; - let rank = rank.parse().with_context(|| format!("invalid rank: {}", rank))?; + let rank = split.next().with_context(|| format!("invalid entry: {line}"))?; + let rank = rank.parse().with_context(|| format!("invalid rank: {rank}"))?; - let path = split.next().with_context(|| format!("invalid entry: {}", line))?; + let path = split.next().with_context(|| format!("invalid entry: {line}"))?; db.dirs.push(Dir { path: path.into(), rank, last_accessed }); db.modified = true; diff --git a/src/cmd/init.rs b/src/cmd/init.rs index 36fa7e5..b8ae591 100644 --- a/src/cmd/init.rs +++ b/src/cmd/init.rs @@ -26,6 +26,6 @@ impl Run for Init { InitShell::Zsh => shell::Zsh(opts).render(), } .context("could not render template")?; - writeln!(io::stdout(), "{}", source).pipe_exit("stdout") + writeln!(io::stdout(), "{source}").pipe_exit("stdout") } } diff --git a/src/cmd/query.rs b/src/cmd/query.rs index a584095..4f509ba 100644 --- a/src/cmd/query.rs +++ b/src/cmd/query.rs @@ -45,10 +45,10 @@ impl Query { }; if self.score { - print!("{}", selection); + print!("{selection}"); } else { let path = selection.get(5..).context("could not read selection from fzf")?; - print!("{}", path); + print!("{path}"); } } else if self.list { let handle = &mut io::stdout().lock(); diff --git a/src/cmd/remove.rs b/src/cmd/remove.rs index 189e937..a3fd695 100644 --- a/src/cmd/remove.rs +++ b/src/cmd/remove.rs @@ -34,7 +34,8 @@ impl Run for Remove { let paths = selection.lines().filter_map(|line| line.get(5..)); for path in paths { if !db.remove(path) { - bail!("path not found in database: {}", path); + db.modified = false; + bail!("path not found in database: {path}"); } } } else { @@ -42,8 +43,9 @@ impl Run for Remove { if !db.remove(path) { let path_abs = util::resolve_path(path)?; let path_abs = util::path_to_str(&path_abs)?; - if path_abs != path && !db.remove(path_abs) { - bail!("path not found in database: {} ({})", path, path_abs) + if path_abs == path || !db.remove(path_abs) { + db.modified = false; + bail!("path not found in database: {path}") } } } diff --git a/src/config.rs b/src/config.rs index ce63c93..e4fb6be 100644 --- a/src/config.rs +++ b/src/config.rs @@ -24,7 +24,7 @@ pub fn exclude_dirs() -> Result> { Some(paths) => env::split_paths(&paths) .map(|path| { let pattern = path.to_str().context("invalid unicode in _ZO_EXCLUDE_DIRS")?; - Pattern::new(pattern).with_context(|| format!("invalid glob in _ZO_EXCLUDE_DIRS: {}", pattern)) + Pattern::new(pattern).with_context(|| format!("invalid glob in _ZO_EXCLUDE_DIRS: {pattern}")) }) .collect(), None => { @@ -46,7 +46,7 @@ pub fn maxage() -> Result { env::var_os("_ZO_MAXAGE").map_or(Ok(10_000.0), |maxage| { let maxage = maxage.to_str().context("invalid unicode in _ZO_MAXAGE")?; let maxage = - maxage.parse::().with_context(|| format!("unable to parse _ZO_MAXAGE as integer: {}", maxage))?; + maxage.parse::().with_context(|| format!("unable to parse _ZO_MAXAGE as integer: {maxage}"))?; Ok(maxage as Rank) }) } diff --git a/src/db/dir.rs b/src/db/dir.rs index f9ddb10..e2eee3d 100644 --- a/src/db/dir.rs +++ b/src/db/dir.rs @@ -34,7 +34,7 @@ impl DirList<'_> { match version { Self::VERSION => Ok(deserializer.deserialize(bytes_dirs)?), version => { - bail!("unsupported version (got {}, supports {})", version, Self::VERSION,) + bail!("unsupported version (got {version}, supports {})", Self::VERSION) } } })() diff --git a/src/error.rs b/src/error.rs index 61ff0e4..563689b 100644 --- a/src/error.rs +++ b/src/error.rs @@ -22,7 +22,7 @@ impl BrokenPipeHandler for io::Result<()> { fn pipe_exit(self, device: &str) -> Result<()> { match self { Err(e) if e.kind() == io::ErrorKind::BrokenPipe => bail!(SilentExit { code: 0 }), - result => result.with_context(|| format!("could not write to {}", device)), + result => result.with_context(|| format!("could not write to {device}")), } } }