Added better output in query when already in the matched directory

This commit is contained in:
Priyanshu Verma 2022-10-02 16:07:35 +05:30
parent c3e3c855ca
commit 33120f8333
1 changed files with 19 additions and 3 deletions

View File

@ -1,6 +1,8 @@
use std::io::{self, Write};
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use std::env;
use std::io::{self, Write};
use std::path::PathBuf;
use std::str::FromStr;
use crate::cmd::{Query, Run}; use crate::cmd::{Query, Run};
use crate::config; use crate::config;
@ -64,7 +66,21 @@ impl Query {
} }
handle.flush().pipe_exit("stdout")?; handle.flush().pipe_exit("stdout")?;
} else { } else {
let dir = stream.next().context("no match found")?; let excluded_dir = self.exclude.as_ref().map_or(PathBuf::new(), |path| PathBuf::from_str(path).unwrap());
let try_dir = stream.next();
let dir = match try_dir {
Some(dir) => dir,
None => {
// Current Directory is passed as excluded in __zoxide_z
if excluded_dir == env::current_dir()? {
try_dir.context("already in the matched directory")?
} else {
try_dir.context("no match found")?
}
}
};
if self.score { if self.score {
writeln!(io::stdout(), "{}", dir.display_score(now)) writeln!(io::stdout(), "{}", dir.display_score(now))
} else { } else {