1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-06-07 11:00:47 +00:00

feat: Add AWS module (#419)

Adds a module for displaying the current AWS profile based 
on the AWS_PROFILE envar.
This commit is contained in:
Thomas O'Donnell 2019-09-26 04:55:47 +02:00 committed by Kevin Song
parent 80a9e7b9a6
commit b050c59708
7 changed files with 83 additions and 0 deletions

View File

@ -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.

View File

@ -6,6 +6,7 @@ use std::fmt;
// List of all modules
pub const ALL_MODULES: &[&str] = &[
"aws",
#[cfg(feature = "battery")]
"battery",
"character",

29
src/modules/aws.rs Normal file
View File

@ -0,0 +1,29 @@
use std::env;
use ansi_term::Color;
use super::{Context, Module};
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
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)
}

View File

@ -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<Module<'a>> {
match module {
"aws" => aws::module(context),
"directory" => directory::module(context),
"character" => character::module(context),
"nodejs" => nodejs::module(context),

View File

@ -15,6 +15,7 @@ const DEFAULT_PROMPT_ORDER: &[&str] = &[
"username",
"hostname",
"directory",
"aws",
"git_branch",
"git_state",
"git_status",

25
tests/testsuite/aws.rs Normal file
View File

@ -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(())
}

View File

@ -1,3 +1,4 @@
mod aws;
mod character;
mod cmd_duration;
mod common;