Show commit hash in version when built from source

Users might file an issue while running an older version, but the issue
has already been fixed in master. Adding the git revision to the version
output will expedite this diagnosis. For example:

    $ zoxide -V
    zoxide 0.3.0-0191eea
This commit is contained in:
Cole Helbling 2020-03-30 17:31:37 -07:00
parent 0191eead52
commit 030bb57924
No known key found for this signature in database
GPG Key ID: B37E0F2371016A4C
2 changed files with 18 additions and 1 deletions

14
build.rs Normal file
View File

@ -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);
}

View File

@ -8,7 +8,10 @@ use anyhow::Result;
use structopt::StructOpt; use structopt::StructOpt;
#[derive(Debug, 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 { enum Zoxide {
Add(subcommand::Add), Add(subcommand::Add),
Import(subcommand::Import), Import(subcommand::Import),