feat: Add configuration for hostname truncation (#485)

This commit is contained in:
Zach Mertes
2019-10-14 12:22:25 -04:00
committed by Matan Kushner
parent 4634449354
commit 5303fd7684
4 changed files with 70 additions and 7 deletions
+2
View File
@@ -8,6 +8,7 @@ pub struct HostnameConfig<'a> {
pub ssh_only: bool,
pub prefix: &'a str,
pub suffix: &'a str,
pub trim_at: &'a str,
pub style: Style,
pub disabled: bool,
}
@@ -18,6 +19,7 @@ impl<'a> RootModuleConfig<'a> for HostnameConfig<'a> {
ssh_only: true,
prefix: "",
suffix: "",
trim_at: ".",
style: Color::Green.bold().dimmed(),
disabled: false,
}
+14
View File
@@ -30,6 +30,20 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
}
};
let trim_at = module.config_value_str("trim_at").unwrap_or(".");
//rustc doesn't let you do an "if" and an "if let" in the same if statement
// if this changes in the future this can become a lot cleaner
let host = if config.trim_at != "" {
if let Some(index) = host.find(config.trim_at) {
host.split_at(index).0
} else {
host.as_ref()
}
} else {
host.as_ref()
};
module.set_style(config.style);
module.new_segment(
"hostname",