diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..f167873 --- /dev/null +++ b/build.rs @@ -0,0 +1,14 @@ +fn main() { + let mut hash = std::process::Command::new("git") + .args(&["rev-parse", "--short", "HEAD"]) + .output() + .ok() + .and_then(|proc| String::from_utf8(proc.stdout).ok()) + .unwrap_or_default(); + + if !hash.is_empty() { + hash = format!("-{}", hash); + } + + println!("cargo:rustc-env=GIT_HASH={}", hash); +} diff --git a/src/main.rs b/src/main.rs index a480b45..63e617e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,10 @@ use anyhow::Result; use structopt::StructOpt; #[derive(Debug, StructOpt)] -#[structopt(about = "A cd command that learns your habits")] +#[structopt( + about = "A cd command that learns your habits", + version = concat!(env!("CARGO_PKG_VERSION"), env!("GIT_HASH")) +)] enum Zoxide { Add(subcommand::Add), Import(subcommand::Import),