This commit is contained in:
2022-10-14 22:28:27 +02:00
commit cb3bd469db
4 changed files with 173 additions and 0 deletions

44
src/main.rs Normal file
View File

@@ -0,0 +1,44 @@
use std::{path::PathBuf, string};
fn main() -> eyre::Result<()> {
// Choose dir
let root_dir = "/home/kjuulh/git/";
let mut projects: Vec<PathBuf> = vec![];
let pattern = regex::Regex::new(".*\\.git$")?;
// Look for dir .git if found add path to map
for entry in walkdir::WalkDir::new(root_dir)
.follow_links(true)
.into_iter()
.filter_map(|e| e.ok())
{
let metadata = entry.metadata()?;
if metadata.is_dir() {
let name = entry.file_name().to_string_lossy();
if pattern.is_match(&name) {
projects.push(entry.into_path())
}
}
}
// Print
println!("writing projects");
let projects_str = projects
.into_iter()
.map(|mut p| {
p.pop();
p
})
.map(|p| p.to_string_lossy().to_string())
.collect::<Vec<String>>();
let content = projects_str.join("\n");
std::fs::write(
"/home/kjuulh/.local/share/nvim/project_nvim/project_history",
content,
)?;
Ok(())
}