diff --git a/docs/config/README.md b/docs/config/README.md index be0bce93..d21df11b 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -84,6 +84,7 @@ prompt_order = [ "username", "hostname", "directory", + "aws", "git_branch", "git_state", "git_status", @@ -104,6 +105,29 @@ prompt_order = [ ] ``` +## AWS + +The `aws` module shows the current AWS profile. This is based on the +`AWS_PROFILE` env var. + +### Options + +| Variable | Default | Description | +| ---------- | --------------- | ---------------------------------------------------- | +| `disabled` | `false` | Disables the `AWS` module | +| `style` | `"bold yellow"` | The style used for the module | +| `symbol` | `"☁️ "` | The symbol before displaying the current AWS profile | + +### Example + +```toml +# ~/.config/starship.toml + +[aws] +style = "bold blue" +symbol = "🅰 " +``` + ## Battery The `battery` module shows how charged the device's battery is and its current charging status. diff --git a/src/module.rs b/src/module.rs index 2cda82a0..47c5eabf 100644 --- a/src/module.rs +++ b/src/module.rs @@ -6,6 +6,7 @@ use std::fmt; // List of all modules pub const ALL_MODULES: &[&str] = &[ + "aws", #[cfg(feature = "battery")] "battery", "character", diff --git a/src/modules/aws.rs b/src/modules/aws.rs new file mode 100644 index 00000000..65ca0514 --- /dev/null +++ b/src/modules/aws.rs @@ -0,0 +1,29 @@ +use std::env; + +use ansi_term::Color; + +use super::{Context, Module}; + +pub fn module<'a>(context: &'a Context) -> Option> { + const AWS_CHAR: &str = "☁️ "; + const AWS_PREFIX: &str = "on "; + + let aws_profile = env::var("AWS_PROFILE").ok()?; + if aws_profile.is_empty() { + return None; + } + + let mut module = context.new_module("aws"); + + let module_style = module + .config_value_style("style") + .unwrap_or_else(|| Color::Yellow.bold()); + module.set_style(module_style); + + module.get_prefix().set_value(AWS_PREFIX); + + module.new_segment("symbol", AWS_CHAR); + module.new_segment("profile", &aws_profile); + + Some(module) +} diff --git a/src/modules/mod.rs b/src/modules/mod.rs index 40590618..c1618252 100644 --- a/src/modules/mod.rs +++ b/src/modules/mod.rs @@ -1,4 +1,5 @@ // While adding out new module add out module to src/module.rs ALL_MODULES const array also. +mod aws; mod character; mod cmd_duration; mod directory; @@ -27,6 +28,7 @@ use crate::module::Module; pub fn handle<'a>(module: &str, context: &'a Context) -> Option> { match module { + "aws" => aws::module(context), "directory" => directory::module(context), "character" => character::module(context), "nodejs" => nodejs::module(context), diff --git a/src/print.rs b/src/print.rs index 12e98fb2..1c7e4670 100644 --- a/src/print.rs +++ b/src/print.rs @@ -15,6 +15,7 @@ const DEFAULT_PROMPT_ORDER: &[&str] = &[ "username", "hostname", "directory", + "aws", "git_branch", "git_state", "git_status", diff --git a/tests/testsuite/aws.rs b/tests/testsuite/aws.rs new file mode 100644 index 00000000..d02bccca --- /dev/null +++ b/tests/testsuite/aws.rs @@ -0,0 +1,25 @@ +use ansi_term::Color; +use std::io; + +use crate::common; + +#[test] +fn no_profile_set() -> io::Result<()> { + let output = common::render_module("aws").env_clear().output()?; + let expected = ""; + let actual = String::from_utf8(output.stdout).unwrap(); + assert_eq!(expected, actual); + Ok(()) +} + +#[test] +fn profile_set() -> io::Result<()> { + let output = common::render_module("aws") + .env_clear() + .env("AWS_PROFILE", "astronauts") + .output()?; + let expected = format!("on {} ", Color::Yellow.bold().paint("☁️ astronauts")); + let actual = String::from_utf8(output.stdout).unwrap(); + assert_eq!(expected, actual); + Ok(()) +} diff --git a/tests/testsuite/main.rs b/tests/testsuite/main.rs index d299ca61..89f573f9 100644 --- a/tests/testsuite/main.rs +++ b/tests/testsuite/main.rs @@ -1,3 +1,4 @@ +mod aws; mod character; mod cmd_duration; mod common;