From df33df6c95471379dba7312cbacaf44f7bb4f74d Mon Sep 17 00:00:00 2001 From: NerdyPepper Date: Sun, 19 May 2019 21:40:33 +0530 Subject: added vcs status --- src/main.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6ddfe0f..65a293d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,13 @@ use std::env; use tico::tico; +use git2::Repository; fn main() { - println!("{}", cwd()); + print!("{}", cwd()); + match vcs() { + Some(br) => println!(" {}", br), + None => println!() + } println!("{}", prompt_char()); } @@ -27,5 +32,21 @@ fn prompt_char() -> String { } } -fn vcs() -> String { +fn vcs() -> Option { + let current_dir = env::var("PWD").unwrap(); + + let repo = match Repository::open(current_dir) { + Ok(r) => r, + Err(_) => return None + }; + + let reference = repo.head().unwrap(); + + if reference.is_branch() { + Some(format!("{}", reference.shorthand().unwrap())) + } else { + let commit = reference.peel_to_commit().unwrap(); + let id = commit.id(); + Some(format!("{}", id)) + } } -- cgit v1.2.3