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:
parent
80a9e7b9a6
commit
b050c59708
|
@ -84,6 +84,7 @@ prompt_order = [
|
||||||
"username",
|
"username",
|
||||||
"hostname",
|
"hostname",
|
||||||
"directory",
|
"directory",
|
||||||
|
"aws",
|
||||||
"git_branch",
|
"git_branch",
|
||||||
"git_state",
|
"git_state",
|
||||||
"git_status",
|
"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
|
## Battery
|
||||||
|
|
||||||
The `battery` module shows how charged the device's battery is and its current charging status.
|
The `battery` module shows how charged the device's battery is and its current charging status.
|
||||||
|
|
|
@ -6,6 +6,7 @@ use std::fmt;
|
||||||
|
|
||||||
// List of all modules
|
// List of all modules
|
||||||
pub const ALL_MODULES: &[&str] = &[
|
pub const ALL_MODULES: &[&str] = &[
|
||||||
|
"aws",
|
||||||
#[cfg(feature = "battery")]
|
#[cfg(feature = "battery")]
|
||||||
"battery",
|
"battery",
|
||||||
"character",
|
"character",
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
// While adding out new module add out module to src/module.rs ALL_MODULES const array also.
|
// While adding out new module add out module to src/module.rs ALL_MODULES const array also.
|
||||||
|
mod aws;
|
||||||
mod character;
|
mod character;
|
||||||
mod cmd_duration;
|
mod cmd_duration;
|
||||||
mod directory;
|
mod directory;
|
||||||
|
@ -27,6 +28,7 @@ use crate::module::Module;
|
||||||
|
|
||||||
pub fn handle<'a>(module: &str, context: &'a Context) -> Option<Module<'a>> {
|
pub fn handle<'a>(module: &str, context: &'a Context) -> Option<Module<'a>> {
|
||||||
match module {
|
match module {
|
||||||
|
"aws" => aws::module(context),
|
||||||
"directory" => directory::module(context),
|
"directory" => directory::module(context),
|
||||||
"character" => character::module(context),
|
"character" => character::module(context),
|
||||||
"nodejs" => nodejs::module(context),
|
"nodejs" => nodejs::module(context),
|
||||||
|
|
|
@ -15,6 +15,7 @@ const DEFAULT_PROMPT_ORDER: &[&str] = &[
|
||||||
"username",
|
"username",
|
||||||
"hostname",
|
"hostname",
|
||||||
"directory",
|
"directory",
|
||||||
|
"aws",
|
||||||
"git_branch",
|
"git_branch",
|
||||||
"git_state",
|
"git_state",
|
||||||
"git_status",
|
"git_status",
|
||||||
|
|
|
@ -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(())
|
||||||
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
|
mod aws;
|
||||||
mod character;
|
mod character;
|
||||||
mod cmd_duration;
|
mod cmd_duration;
|
||||||
mod common;
|
mod common;
|
||||||
|
|
Loading…
Reference in New Issue