diff options
author | NerdyPepper <[email protected]> | 2019-05-19 17:10:33 +0100 |
---|---|---|
committer | NerdyPepper <[email protected]> | 2019-05-19 17:10:33 +0100 |
commit | df33df6c95471379dba7312cbacaf44f7bb4f74d (patch) | |
tree | 0852c42f763c6ecf893c1572121736b47258c25b | |
parent | 01ede50477eee80767717592a738db772d25b631 (diff) |
added vcs status
-rw-r--r-- | src/main.rs | 25 |
1 files 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 @@ | |||
1 | use std::env; | 1 | use std::env; |
2 | use tico::tico; | 2 | use tico::tico; |
3 | use git2::Repository; | ||
3 | 4 | ||
4 | fn main() { | 5 | fn main() { |
5 | println!("{}", cwd()); | 6 | print!("{}", cwd()); |
7 | match vcs() { | ||
8 | Some(br) => println!(" {}", br), | ||
9 | None => println!() | ||
10 | } | ||
6 | println!("{}", prompt_char()); | 11 | println!("{}", prompt_char()); |
7 | } | 12 | } |
8 | 13 | ||
@@ -27,5 +32,21 @@ fn prompt_char() -> String { | |||
27 | } | 32 | } |
28 | } | 33 | } |
29 | 34 | ||
30 | fn vcs() -> String { | 35 | fn vcs() -> Option<String> { |
36 | let current_dir = env::var("PWD").unwrap(); | ||
37 | |||
38 | let repo = match Repository::open(current_dir) { | ||
39 | Ok(r) => r, | ||
40 | Err(_) => return None | ||
41 | }; | ||
42 | |||
43 | let reference = repo.head().unwrap(); | ||
44 | |||
45 | if reference.is_branch() { | ||
46 | Some(format!("{}", reference.shorthand().unwrap())) | ||
47 | } else { | ||
48 | let commit = reference.peel_to_commit().unwrap(); | ||
49 | let id = commit.id(); | ||
50 | Some(format!("{}", id)) | ||
51 | } | ||
31 | } | 52 | } |