mirror of
https://github.com/Llewellynvdm/zoxide.git
synced 2024-12-28 11:50:56 +00:00
Fix remove not throwing errors
This commit is contained in:
parent
e4aa0692a4
commit
e8a1e11848
6
build.rs
6
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.
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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::<f64>().with_context(|| format!("invalid rank: {}", rank))?;
|
||||
let rank = split.next().with_context(|| format!("invalid entry: {line}"))?;
|
||||
let mut rank = rank.parse::<f64>().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;
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ pub fn exclude_dirs() -> Result<Vec<Pattern>> {
|
||||
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<Rank> {
|
||||
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::<u32>().with_context(|| format!("unable to parse _ZO_MAXAGE as integer: {}", maxage))?;
|
||||
maxage.parse::<u32>().with_context(|| format!("unable to parse _ZO_MAXAGE as integer: {maxage}"))?;
|
||||
Ok(maxage as Rank)
|
||||
})
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
})()
|
||||
|
@ -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}")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user