added support for displaying tags behind branch name
This commit is contained in:
parent
c8803ad0ae
commit
5b6d1e3795
|
|
@ -35,7 +35,7 @@ checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125"
|
|||
|
||||
[[package]]
|
||||
name = "fast-git-prompt"
|
||||
version = "0.1.0"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"git2",
|
||||
"regex",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "fast-git-prompt"
|
||||
version = "0.1.1"
|
||||
version = "0.2.0"
|
||||
description = "A fast git prompt for zsh and bash."
|
||||
license = "MIT"
|
||||
repository = "https://github.com/MasterGordon/fast-git-prompt"
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use crate::colors::{color, Color};
|
||||
use crate::prompt_parts::prompt_part::RenderablePromptPart;
|
||||
use git2::Repository;
|
||||
use schemars::JsonSchema;
|
||||
|
|
@ -5,7 +6,7 @@ use serde::{Deserialize, Serialize};
|
|||
|
||||
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct BranchName {
|
||||
pub color: Option<String>,
|
||||
pub color: Option<Color>,
|
||||
}
|
||||
|
||||
impl RenderablePromptPart for BranchName {
|
||||
|
|
@ -16,6 +17,25 @@ impl RenderablePromptPart for BranchName {
|
|||
}?;
|
||||
let name = head.name()?;
|
||||
let last = name.split('/').last()?;
|
||||
return Some(format!("{}{}", self.color.unwrap_or("".to_string()), last));
|
||||
let head_commit = head.peel_to_commit().unwrap();
|
||||
let mut current_tags: Vec<String> = vec![];
|
||||
let tag_names = repo.tag_names(None);
|
||||
for tag_name in tag_names.iter().flatten() {
|
||||
let tag_object = repo.revparse_single(&format!("refs/tags/{}", tag_name?));
|
||||
|
||||
if let Ok(tag_commit) = tag_object.unwrap().peel_to_commit() {
|
||||
if head_commit.id() == tag_commit.id() {
|
||||
if let Some(tag) = tag_name {
|
||||
current_tags.push(tag.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let last_tag = current_tags.last();
|
||||
if let Some(tag) = last_tag {
|
||||
return Some(format!("{}{} ({})", color(self.color), last, tag));
|
||||
} else {
|
||||
return Some(format!("{}{}", color(self.color), last));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue