use crate::logger::*;
use std::io;
pub fn run_logs(args: &[String]) -> io::Result<()> {
log_section("Showing recent commits...");
let mut cmd = std::process::Command::new("chezmoi");
cmd.arg("git").arg("--").arg("log");
if args.len() > 2 {
cmd.args(&args[2..]);
cmd.status()?;
} else {
cmd.args(&[
"-n",
"10",
"--color=always",
"--pretty=format:%C(yellow)%h%Creset - %C(cyan)%an%Creset, %C(green)%ar%Creset : %s",
"--shortstat",
]);
let output = cmd.output()?;
if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
eprintln!("{}", stderr);
std::process::exit(output.status.code().unwrap_or(1));
}
let stdout_str = String::from_utf8_lossy(&output.stdout);
let mut lines = stdout_str.lines().map(|s| s.trim()).peekable();
while let Some(line) = lines.next() {
if line.is_empty() {
continue;
}
let has_stats = if let Some(&next_line) = lines.peek() {
next_line.contains("changed")
|| next_line.contains("insertion")
|| next_line.contains("deletion")
} else {
false
};
if has_stats {
let stat_line = lines.next().unwrap();
println!("{} | \x1b[36m{}\x1b[0m", line, stat_line);
} else {
println!("{}", line);
}
}
}
Ok(())
}