@@ 4,16 4,30 @@ use std::io::BufWriter;
use std::io::Error;
use std::io::Write;
use std::path::Path;
+use std::process::Command;
fn main() -> Result<(), Error> {
let mut stdout = BufWriter::new(std::io::stdout());
cwd(&mut stdout)?;
+
+ faint(&mut stdout)?;
+ git(&mut stdout)?;
+ reset(&mut stdout)?;
+
icon(&mut stdout)?;
stdout.flush()
}
+fn faint<W: Write>(mut w: W) -> Result<(), Error> {
+ write!(w, "\x1b[2m")
+}
+
+fn reset<W: Write>(mut w: W) -> Result<(), Error> {
+ write!(w, "\x1b[0m")
+}
+
fn icon<W: Write>(mut w: W) -> Result<(), Error> {
write!(w, "❯ ")
}
@@ 30,3 44,17 @@ fn cwd<W: Write>(mut w: W) -> Result<(), Error> {
}
Ok(())
}
+
+fn git<W: Write>(mut w: W) -> Result<(), Error> {
+ match Command::new("git")
+ .args(["rev-parse", "--abbrev-ref", "HEAD"])
+ .output()
+ {
+ Ok(abbrev_ref) if abbrev_ref.status.success() => {
+ write!(w, "(")?;
+ w.write_all(abbrev_ref.stdout.trim_ascii())?;
+ write!(w, ") ")
+ }
+ _ => Ok(()),
+ }
+}