feat: add singularity module (#932)
This commit is contained in:
parent
15f4202df1
commit
7e66791cb2
|
@ -1091,6 +1091,33 @@ The module will be shown if any of the following conditions are met:
|
||||||
symbol = "⚙️ "
|
symbol = "⚙️ "
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Singularity
|
||||||
|
|
||||||
|
The `singularity` module shows the current singularity image, if inside a container
|
||||||
|
and `$SINGULARITY_NAME` is set.
|
||||||
|
|
||||||
|
:::
|
||||||
|
|
||||||
|
### Options
|
||||||
|
|
||||||
|
| Variable | Default | Description |
|
||||||
|
| ---------- | -------------------- | ------------------------------------------------ |
|
||||||
|
| `label` | `""` | Prefix before the image name display. |
|
||||||
|
| `prefix` | `"["` | Prefix to display immediately before image name. |
|
||||||
|
| `suffix` | `"]"` | Suffix to display immediately after image name. |
|
||||||
|
| `symbol` | `""` | The symbol used before the image name. |
|
||||||
|
| `style` | `"bold dimmed blue"` | The style for the module. |
|
||||||
|
| `disabled` | `false` | Disables the `singularity` module. |
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```toml
|
||||||
|
# ~/.config/starship.toml
|
||||||
|
|
||||||
|
[singularity]
|
||||||
|
symbol = "📦 "
|
||||||
|
```
|
||||||
|
|
||||||
## Terraform
|
## Terraform
|
||||||
|
|
||||||
The `terraform` module shows the currently selected terraform workspace and version.
|
The `terraform` module shows the currently selected terraform workspace and version.
|
||||||
|
|
|
@ -27,6 +27,7 @@ pub mod php;
|
||||||
pub mod python;
|
pub mod python;
|
||||||
pub mod ruby;
|
pub mod ruby;
|
||||||
pub mod rust;
|
pub mod rust;
|
||||||
|
pub mod singularity;
|
||||||
mod starship_root;
|
mod starship_root;
|
||||||
pub mod terraform;
|
pub mod terraform;
|
||||||
pub mod time;
|
pub mod time;
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
use crate::config::{ModuleConfig, RootModuleConfig, SegmentConfig};
|
||||||
|
|
||||||
|
use ansi_term::{Color, Style};
|
||||||
|
use starship_module_config_derive::ModuleConfig;
|
||||||
|
|
||||||
|
#[derive(Clone, ModuleConfig)]
|
||||||
|
pub struct SingularityConfig<'a> {
|
||||||
|
pub symbol: SegmentConfig<'a>,
|
||||||
|
pub label: &'a str,
|
||||||
|
pub prefix: &'a str,
|
||||||
|
pub suffix: &'a str,
|
||||||
|
pub style: Style,
|
||||||
|
pub disabled: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> RootModuleConfig<'a> for SingularityConfig<'a> {
|
||||||
|
fn new() -> Self {
|
||||||
|
SingularityConfig {
|
||||||
|
symbol: SegmentConfig::default(),
|
||||||
|
label: "",
|
||||||
|
prefix: "[",
|
||||||
|
suffix: "]",
|
||||||
|
style: Color::Blue.bold().dimmed(),
|
||||||
|
disabled: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,6 +19,7 @@ impl<'a> RootModuleConfig<'a> for StarshipRootConfig<'a> {
|
||||||
prompt_order: vec![
|
prompt_order: vec![
|
||||||
"username",
|
"username",
|
||||||
"hostname",
|
"hostname",
|
||||||
|
"singularity",
|
||||||
"kubernetes",
|
"kubernetes",
|
||||||
"directory",
|
"directory",
|
||||||
"git_branch",
|
"git_branch",
|
||||||
|
|
|
@ -42,6 +42,7 @@ pub const ALL_MODULES: &[&str] = &[
|
||||||
"rust",
|
"rust",
|
||||||
"php",
|
"php",
|
||||||
"terraform",
|
"terraform",
|
||||||
|
"singularity",
|
||||||
"time",
|
"time",
|
||||||
"username",
|
"username",
|
||||||
];
|
];
|
||||||
|
|
|
@ -28,6 +28,7 @@ mod php;
|
||||||
mod python;
|
mod python;
|
||||||
mod ruby;
|
mod ruby;
|
||||||
mod rust;
|
mod rust;
|
||||||
|
mod singularity;
|
||||||
mod terraform;
|
mod terraform;
|
||||||
mod time;
|
mod time;
|
||||||
mod username;
|
mod username;
|
||||||
|
@ -74,6 +75,7 @@ pub fn handle<'a>(module: &str, context: &'a Context) -> Option<Module<'a>> {
|
||||||
"python" => python::module(context),
|
"python" => python::module(context),
|
||||||
"ruby" => ruby::module(context),
|
"ruby" => ruby::module(context),
|
||||||
"rust" => rust::module(context),
|
"rust" => rust::module(context),
|
||||||
|
"singularity" => singularity::module(context),
|
||||||
"terraform" => terraform::module(context),
|
"terraform" => terraform::module(context),
|
||||||
"time" => time::module(context),
|
"time" => time::module(context),
|
||||||
"crystal" => crystal::module(context),
|
"crystal" => crystal::module(context),
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
use std::env;
|
||||||
|
|
||||||
|
use super::{Context, Module, SegmentConfig};
|
||||||
|
|
||||||
|
use crate::config::RootModuleConfig;
|
||||||
|
use crate::configs::singularity::SingularityConfig;
|
||||||
|
|
||||||
|
/// Creates a module with the current Singularity image
|
||||||
|
///
|
||||||
|
/// Will display the Singularity image if `$SINGULARITY_NAME` is set.
|
||||||
|
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||||
|
let singularity_env = env::var("SINGULARITY_NAME").unwrap_or_else(|_| "".into());
|
||||||
|
if singularity_env.trim().is_empty() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut module = context.new_module("singularity");
|
||||||
|
let config = SingularityConfig::try_load(module.config);
|
||||||
|
|
||||||
|
module.get_prefix().set_value(config.label);
|
||||||
|
module.set_style(config.style);
|
||||||
|
module.create_segment("symbol", &config.symbol);
|
||||||
|
|
||||||
|
let env_var_stacked = format!("{}{}{}", config.prefix, singularity_env, config.suffix);
|
||||||
|
module.create_segment("singularity", &SegmentConfig::new(&env_var_stacked));
|
||||||
|
|
||||||
|
Some(module)
|
||||||
|
}
|
|
@ -18,6 +18,7 @@ mod line_break;
|
||||||
mod modules;
|
mod modules;
|
||||||
mod nix_shell;
|
mod nix_shell;
|
||||||
mod python;
|
mod python;
|
||||||
|
mod singularity;
|
||||||
mod terraform;
|
mod terraform;
|
||||||
mod time;
|
mod time;
|
||||||
mod username;
|
mod username;
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
use ansi_term::Color;
|
||||||
|
use std::io;
|
||||||
|
|
||||||
|
use crate::common;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn env_set() -> io::Result<()> {
|
||||||
|
let output = common::render_module("singularity")
|
||||||
|
.env_clear()
|
||||||
|
.env("SINGULARITY_NAME", "centos.img")
|
||||||
|
.output()?;
|
||||||
|
|
||||||
|
let expected = format!("{} ", Color::Blue.bold().dimmed().paint("[centos.img]"));
|
||||||
|
let actual = String::from_utf8(output.stdout).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(expected, actual);
|
||||||
|
Ok(())
|
||||||
|
}
|
Loading…
Reference in New Issue