diff options
-rw-r--r-- | src/config.rs | 10 | ||||
-rw-r--r-- | src/main.rs | 8 | ||||
-rw-r--r-- | src/project.rs | 8 | ||||
-rw-r--r-- | src/tmux.rs | 15 |
4 files changed, 13 insertions, 28 deletions
diff --git a/src/config.rs b/src/config.rs index c504590..2aa9d67 100644 --- a/src/config.rs +++ b/src/config.rs @@ -18,10 +18,6 @@ pub struct Config { #[arg(short = 'T', long = "sessions")] pub tmux_sessions: bool, - /// Exclude currently attached tmux session from output - #[arg(long)] - pub exclude_attached: bool, - /// Include arbitrary directories in output /// /// Note: Directories added by this flag are still filtered and sorted based on supplied @@ -56,10 +52,14 @@ pub struct Search { #[derive(Debug, Default, Clone, Args)] pub struct Projects { - /// Exclude matching sessions from output + /// Exclude matching sessions from output. #[arg(short, long = "exclude")] pub excludes: Vec<PathBuf>, + /// Exclude current working directory from output. + #[arg(short = 'E', long)] + pub exclude_cwd: bool, + /// Match all child directories. /// /// Uses the directory mtime as the timestamp. diff --git a/src/main.rs b/src/main.rs index a50d3a1..25a051e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ use clap::Parser; use projectr::{config::Config, project::Projects, tmux::Tmux, Search}; fn main() -> Result<()> { - let mut config = Config::parse(); + let config = Config::parse(); tracing_subscriber::fmt::fmt() .pretty() @@ -11,12 +11,6 @@ fn main() -> Result<()> { .with_max_level(&config.verbosity) .init(); - if config.exclude_attached { - if let Ok(path) = Tmux::attached() { - config.parsers.excludes.push(path) - } - } - let mut projects = Projects::from(config.parsers); projects.extend(config.include); diff --git a/src/project.rs b/src/project.rs index a35c17e..7d9357b 100644 --- a/src/project.rs +++ b/src/project.rs @@ -110,7 +110,7 @@ impl Extend<Project> for Projects { } impl From<crate::config::Projects> for Projects { - fn from(value: crate::config::Projects) -> Self { + fn from(mut value: crate::config::Projects) -> Self { let mut filters: Vec<Box<dyn FilterMap>> = Vec::new(); if let Some(pattern) = &value.pattern { @@ -126,6 +126,12 @@ impl From<crate::config::Projects> for Projects { filters.push(Box::new(crate::git::Git)); } + if value.exclude_cwd { + if let Ok(path) = std::env::current_dir() { + value.excludes.push(path) + } + } + Self { filters, excludes: value.excludes, diff --git a/src/tmux.rs b/src/tmux.rs index 6993c2c..559242b 100644 --- a/src/tmux.rs +++ b/src/tmux.rs @@ -24,21 +24,6 @@ impl Tmux { .collect()) } - pub fn attached() -> Result<PathBuf, Error> { - let stdout = Command::new("tmux") - .arg("display") - .arg("-p") - .arg("#{session_path}") - .output()? - .stdout; - - std::str::from_utf8(&stdout)? - .lines() - .map(Into::into) - .last() - .ok_or(Error::NotFound) - } - pub fn get_session(&self, path_buf: PathBuf) -> Result<Project, Error> { let mut filter = OsString::from("#{==:#{session_path},"); filter.push(path_buf.as_os_str()); |