Added option to query only within current directory
This commit is contained in:
parent
c3e3c855ca
commit
8c03027923
|
|
@ -117,6 +117,10 @@ pub struct Query {
|
||||||
#[clap(long, short)]
|
#[clap(long, short)]
|
||||||
pub score: bool,
|
pub score: bool,
|
||||||
|
|
||||||
|
/// Search only through current working directory
|
||||||
|
#[clap(long, short)]
|
||||||
|
pub workingdir: bool,
|
||||||
|
|
||||||
/// Exclude a path from results
|
/// Exclude a path from results
|
||||||
#[clap(long, value_hint = ValueHint::DirPath, value_name = "path")]
|
#[clap(long, value_hint = ValueHint::DirPath, value_name = "path")]
|
||||||
pub exclude: Option<String>,
|
pub exclude: Option<String>,
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,9 @@ impl Query {
|
||||||
if let Some(path) = &self.exclude {
|
if let Some(path) = &self.exclude {
|
||||||
stream = stream.with_exclude(path);
|
stream = stream.with_exclude(path);
|
||||||
}
|
}
|
||||||
|
if self.workingdir {
|
||||||
|
stream = stream.with_workingdir(self.workingdir);
|
||||||
|
}
|
||||||
|
|
||||||
if self.interactive {
|
if self.interactive {
|
||||||
let mut fzf = Fzf::new(false)?;
|
let mut fzf = Fzf::new(false)?;
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@ use std::{fs, path};
|
||||||
use crate::db::{Database, Dir, Epoch};
|
use crate::db::{Database, Dir, Epoch};
|
||||||
use crate::util;
|
use crate::util;
|
||||||
|
|
||||||
|
use std::env;
|
||||||
|
|
||||||
pub struct Stream<'db, 'file> {
|
pub struct Stream<'db, 'file> {
|
||||||
db: &'db mut Database<'file>,
|
db: &'db mut Database<'file>,
|
||||||
idxs: Rev<Range<usize>>,
|
idxs: Rev<Range<usize>>,
|
||||||
|
|
@ -14,6 +16,7 @@ pub struct Stream<'db, 'file> {
|
||||||
check_exists: bool,
|
check_exists: bool,
|
||||||
expire_below: Epoch,
|
expire_below: Epoch,
|
||||||
resolve_symlinks: bool,
|
resolve_symlinks: bool,
|
||||||
|
workingdir: bool,
|
||||||
|
|
||||||
exclude_path: Option<String>,
|
exclude_path: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
@ -34,6 +37,7 @@ impl<'db, 'file> Stream<'db, 'file> {
|
||||||
check_exists: false,
|
check_exists: false,
|
||||||
expire_below,
|
expire_below,
|
||||||
resolve_symlinks: false,
|
resolve_symlinks: false,
|
||||||
|
workingdir: false,
|
||||||
exclude_path: None,
|
exclude_path: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -43,6 +47,11 @@ impl<'db, 'file> Stream<'db, 'file> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn with_workingdir(mut self, workingdir: bool) -> Self {
|
||||||
|
self.workingdir = workingdir;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn with_exists(mut self, resolve_symlinks: bool) -> Self {
|
pub fn with_exists(mut self, resolve_symlinks: bool) -> Self {
|
||||||
self.check_exists = true;
|
self.check_exists = true;
|
||||||
self.resolve_symlinks = resolve_symlinks;
|
self.resolve_symlinks = resolve_symlinks;
|
||||||
|
|
@ -74,6 +83,11 @@ impl<'db, 'file> Stream<'db, 'file> {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if working directory only mode is on and do the check if it is a sub directory of the working directory
|
||||||
|
if self.workingdir && !dir.path.starts_with(env::current_dir().unwrap().to_str().unwrap()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
let dir = &self.db.dirs[idx];
|
let dir = &self.db.dirs[idx];
|
||||||
return Some(dir);
|
return Some(dir);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue