aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
blob: a50d3a153dbd4caa656c691c9aa44731ce23d5f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use anyhow::Result;
use clap::Parser;
use projectr::{config::Config, project::Projects, tmux::Tmux, Search};

fn main() -> Result<()> {
    let mut config = Config::parse();

    tracing_subscriber::fmt::fmt()
        .pretty()
        .with_writer(std::io::stderr)
        .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);

    // Workaround due to ignore::WalkBuilder not implementing Default.
    if let Some((init, paths)) = config.search.paths.split_first() {
        let mut search = Search::new(init);

        for path in paths {
            search.add(path);
        }

        search.max_depth(config.search.max_depth);
        search.hidden(!config.search.hidden);

        projects.extend(search);
    }

    if config.tmux_sessions {
        if let Ok(sessions) = Tmux::sessions() {
            projects.extend(sessions)
        }
    }

    Ok(projects.write(std::io::stdout())?)
}