Working on project type detection
This commit is contained in:
parent
a24962007b
commit
9d19cdd5f8
1
.gitignore
vendored
1
.gitignore
vendored
@ -9,3 +9,4 @@ waycast.toml
|
||||
xdg
|
||||
# For when I have to test nix builds
|
||||
result
|
||||
devicons
|
||||
|
1015
Cargo.lock
generated
1015
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
6
Makefile
6
Makefile
@ -157,3 +157,9 @@ docs: ## Build and open documentation
|
||||
tools: ## Install useful development tools
|
||||
cargo install cargo-watch cargo-audit cargo-machete cargo-flamegraph cargo-deb cargo-outdated
|
||||
@echo "Development tools installed!"
|
||||
|
||||
nix-install:
|
||||
nix profile install .
|
||||
|
||||
nix-reinstall:
|
||||
nix profile install --reinstall .
|
@ -18,6 +18,7 @@ tokio = { version = "1.0", features = [
|
||||
"sync",
|
||||
] }
|
||||
walkdir = "2.5.0"
|
||||
tokei = "12.1.2"
|
||||
|
||||
[lints.rust]
|
||||
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(rust_analyzer)'] }
|
||||
|
46
waycast-plugins/src/main.rs
Normal file
46
waycast-plugins/src/main.rs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user