mirror of
https://github.com/starship/starship.git
synced 2026-06-23 02:05:51 +07:00
feat: Add configuration for hostname truncation (#485)
This commit is contained in:
committed by
Matan Kushner
parent
4634449354
commit
5303fd7684
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user