Working on project type detection

This commit is contained in:
Javier Feliz 2025-09-11 00:24:38 -04:00
parent a24962007b
commit 9d19cdd5f8
5 changed files with 1058 additions and 13 deletions

1
.gitignore vendored
View File

@ -9,3 +9,4 @@ waycast.toml
xdg xdg
# For when I have to test nix builds # For when I have to test nix builds
result result
devicons

1015
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -156,4 +156,10 @@ docs: ## Build and open documentation
# Development tools installation # Development tools installation
tools: ## Install useful development tools tools: ## Install useful development tools
cargo install cargo-watch cargo-audit cargo-machete cargo-flamegraph cargo-deb cargo-outdated cargo install cargo-watch cargo-audit cargo-machete cargo-flamegraph cargo-deb cargo-outdated
@echo "Development tools installed!" @echo "Development tools installed!"
nix-install:
nix profile install .
nix-reinstall:
nix profile install --reinstall .

View File

@ -18,6 +18,7 @@ tokio = { version = "1.0", features = [
"sync", "sync",
] } ] }
walkdir = "2.5.0" walkdir = "2.5.0"
tokei = "12.1.2"
[lints.rust] [lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(rust_analyzer)'] } unexpected_cfgs = { level = "warn", check-cfg = ['cfg(rust_analyzer)'] }

View File

@ -0,0 +1,46 @@
use std::{collections::BTreeMap, path::PathBuf};
use tokei::{Config, LanguageType, Languages};
fn lang_breakdown(paths: &[&str], excluded: &[&str]) -> Vec<(LanguageType, usize, f64)> {
let mut langs = Languages::new();
let cfg = Config::default();
langs.get_statistics(paths, excluded, &cfg);
let total_code: usize = langs.iter().map(|(_, l)| l.code).sum();
let mut rows: Vec<_> = langs
.iter()
.map(|(lt, l)| {
(
*lt,
l.code,
if total_code > 0 {
(l.code as f64) * 100.0 / (total_code as f64)
} else {
0.0
},
)
})
.collect();
rows.sort_by_key(|(_, lines, _)| std::cmp::Reverse(*lines));
rows
}
pub fn main() {
if let Ok(entries) = std::fs::read_dir(PathBuf::from("/home/javi/projects")) {
for e in entries
.into_iter()
.filter(|e| e.is_ok())
.map(|e| e.unwrap())
{
let langs = lang_breakdown(&[e.path().to_str().unwrap()], &[]);
let top = langs
.iter()
.map(|(l, _, _)| l.to_owned())
.take(3)
.collect::<Vec<LanguageType>>();
println!("{}: {:?}", e.path().display(), top);
}
}
}