starship/src/modules/git_branch.rs

23 lines
662 B
Rust
Raw Normal View History

use ansi_term::Color;
2019-05-01 20:34:24 +00:00
use super::{Context, Module};
/// Creates a segment with the Git branch in the current directory
///
/// Will display the branch name if the current directory is a git repo
2019-05-01 20:34:24 +00:00
pub fn segment(context: &Context) -> Option<Module> {
2019-05-14 04:43:11 +00:00
let branch_name = context.branch_name.as_ref()?;
2019-05-14 04:43:11 +00:00
const GIT_BRANCH_CHAR: &str = "";
let segment_color = Color::Purple.bold();
2019-05-14 04:43:11 +00:00
let mut module = Module::new("git_branch");
module.set_style(segment_color);
module.get_prefix().set_value("on ");
2019-05-14 04:43:11 +00:00
module.new_segment("branch_char", GIT_BRANCH_CHAR);
module.new_segment("branch_name", branch_name.to_string());
2019-05-14 04:43:11 +00:00
Some(module)
}