Skip to content

Commit be31a05

Browse files
feat: simplify pre-commit output with Nerd Font file icons
Replace verbose generation change warnings with clean, LLM-friendly output. Add file type icons for 50+ extensions organized by category.
1 parent c604e96 commit be31a05

1 file changed

Lines changed: 98 additions & 41 deletions

File tree

src/main.rs

Lines changed: 98 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,58 +1986,115 @@ fn run_pre_push() {
19861986
std::process::exit(0);
19871987
}
19881988

1989-
fn show_and_apply_jobs(jobs: &mut [Job]) {
1990-
use std::io::{self, Write};
1991-
1992-
const ACTION_REQUIRED: &str = "🚧";
1993-
const OK: &str = "✅";
1994-
const CANCEL: &str = "🛑";
1989+
/// Returns a Nerd Font icon for the given file extension
1990+
fn icon_for_extension(ext: &str) -> &'static str {
1991+
match ext {
1992+
// Languages
1993+
"rs" => "\u{e7a8}", // Rust
1994+
"js" => "\u{e74e}", // JavaScript
1995+
"ts" => "\u{e628}", // TypeScript
1996+
"jsx" | "tsx" => "\u{e7ba}", // React
1997+
"py" => "\u{e73c}", // Python
1998+
"rb" => "\u{e791}", // Ruby
1999+
"go" => "\u{e626}", // Go
2000+
"java" => "\u{e738}", // Java
2001+
"c" | "h" => "\u{e61e}", // C
2002+
"cpp" | "cc" | "cxx" | "hpp" => "\u{e61d}", // C++
2003+
"cs" => "\u{f031b}", // 󰌛 C#
2004+
"swift" => "\u{e755}", // Swift
2005+
"kt" | "kts" => "\u{e634}", // Kotlin
2006+
"php" => "\u{e73d}", // PHP
2007+
"lua" => "\u{e620}", // Lua
2008+
"zig" => "\u{e6a9}", // Zig
2009+
"hs" => "\u{e777}", // Haskell
2010+
"ex" | "exs" => "\u{e62d}", // Elixir
2011+
"erl" => "\u{e7b1}", // Erlang
2012+
"scala" => "\u{e737}", // Scala
2013+
"clj" | "cljs" => "\u{e768}", // Clojure
2014+
"r" => "\u{f07d4}", // 󰟔 R
2015+
"jl" => "\u{e624}", // Julia
2016+
"pl" | "pm" => "\u{e769}", // Perl
2017+
"sh" | "bash" | "zsh" => "\u{e795}", // Shell
2018+
"fish" => "\u{f489}", // Fish
2019+
"ps1" => "\u{e70f}", // PowerShell
2020+
"vim" => "\u{e62b}", // Vim
2021+
"el" => "\u{e779}", // Emacs Lisp
2022+
2023+
// Web
2024+
"html" | "htm" => "\u{e736}", // HTML
2025+
"css" => "\u{e749}", // CSS
2026+
"scss" | "sass" => "\u{e74b}", // Sass
2027+
"less" => "\u{e758}", // Less
2028+
"vue" => "\u{e6a0}", // Vue
2029+
"svelte" => "\u{e697}", // Svelte
2030+
"astro" => "\u{e6b3}", // Astro
2031+
"wasm" => "\u{e6a1}", // WebAssembly
2032+
2033+
// Data/Config
2034+
"json" => "\u{e60b}", // JSON
2035+
"yaml" | "yml" => "\u{e6a8}", // YAML
2036+
"toml" => "\u{e6b2}", // TOML
2037+
"xml" => "\u{f05c0}", // 󰗀 XML
2038+
"csv" => "\u{f0219}", // 󰈙 CSV
2039+
"sql" => "\u{e706}", // SQL
2040+
"graphql" | "gql" => "\u{e662}", // GraphQL
2041+
"proto" => "\u{e6a5}", // Protobuf
2042+
2043+
// Documentation
2044+
"md" | "markdown" => "\u{e73e}", // Markdown
2045+
"txt" => "\u{f0219}", // 󰈙 Text
2046+
"pdf" => "\u{f0226}", // 󰈦 PDF
2047+
"doc" | "docx" => "\u{f0219}", // 󰈙 Word
2048+
"rst" => "\u{f0219}", // 󰈙 reStructuredText
2049+
2050+
// Build/Package
2051+
"lock" => "\u{f023}", // Lock file
2052+
"dockerfile" => "\u{e7b0}", // Docker
2053+
"nix" => "\u{f313}", // Nix
2054+
"cmake" => "\u{e615}", // CMake
2055+
2056+
// Images
2057+
"png" | "jpg" | "jpeg" | "gif" | "bmp" | "ico" | "webp" => "\u{f03e}", // Image
2058+
"svg" => "\u{f0721}", // 󰜡 SVG
2059+
2060+
// Git
2061+
"gitignore" | "gitattributes" | "gitmodules" => "\u{e702}", // Git
2062+
2063+
// Default
2064+
_ => "\u{f15b}", // Generic file
2065+
}
2066+
}
19952067

2068+
fn show_and_apply_jobs(jobs: &mut [Job]) {
19962069
jobs.sort_by_key(|job| job.path.clone());
19972070

19982071
if jobs.is_empty() {
19992072
println!("{}", "All generated files are up-to-date".green().bold());
20002073
return;
20012074
}
20022075

2003-
println!(
2004-
"\n{}\n{}\n",
2005-
format_args!("{ACTION_REQUIRED} GENERATION CHANGES {ACTION_REQUIRED}")
2006-
.on_black()
2007-
.bold()
2008-
.yellow()
2009-
.italic()
2010-
.underline(),
2011-
format_args!(
2012-
"The following {} file{} will be updated/generated:",
2013-
jobs.len(),
2014-
if jobs.len() == 1 { "" } else { "s" }
2015-
)
2016-
.magenta()
2017-
);
2018-
for (idx, job) in jobs.iter().enumerate() {
2019-
println!(
2020-
" {}. {}",
2021-
(idx + 1).bold().cyan(),
2022-
job.path.display().yellow(),
2023-
);
2076+
// Apply all jobs first
2077+
for job in jobs.iter() {
2078+
if let Err(e) = job.apply() {
2079+
eprintln!("Failed to apply {}: {e}", job.path.display());
2080+
std::process::exit(1);
2081+
}
20242082
}
20252083

2026-
let jobs_vec = jobs.to_vec();
2027-
2028-
for job in &jobs_vec {
2029-
print!("{} Applying {} ... ", OK, job.path.display().yellow());
2030-
io::stdout().flush().unwrap();
2031-
match job.apply() {
2032-
Ok(_) => {
2033-
println!("{}", "ok".green());
2034-
}
2035-
Err(e) => {
2036-
println!("{} {}", CANCEL, format_args!("failed: {e}").red());
2037-
}
2038-
}
2084+
// Print clean summary
2085+
println!(
2086+
"\n{}",
2087+
"These files have been automatically formatted and staged:".green()
2088+
);
2089+
for job in jobs.iter() {
2090+
let ext = job.path.extension().and_then(|e| e.to_str()).unwrap_or("");
2091+
let icon = icon_for_extension(ext);
2092+
println!(" {} {}", icon.cyan(), job.path.display());
20392093
}
2040-
println!("{} {}", OK, "All fixes applied and staged!".green().bold());
2094+
println!(
2095+
"\n{}",
2096+
"The commit is ready to push - no 'git amend' is necessary.".green()
2097+
);
20412098
std::process::exit(0);
20422099
}
20432100

0 commit comments

Comments
 (0)