From 33120f8333b4efed639085be86b402eae2032b2a Mon Sep 17 00:00:00 2001 From: Priyanshu Verma Date: Sun, 2 Oct 2022 16:07:35 +0530 Subject: [PATCH] Added better output in query when already in the matched directory --- src/cmd/query.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/cmd/query.rs b/src/cmd/query.rs index b6a9657..fd7b690 100644 --- a/src/cmd/query.rs +++ b/src/cmd/query.rs @@ -1,6 +1,8 @@ -use std::io::{self, Write}; - 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::config; @@ -64,7 +66,21 @@ impl Query { } handle.flush().pipe_exit("stdout")?; } 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 { writeln!(io::stdout(), "{}", dir.display_score(now)) } else {