mirror of
https://github.com/starship/starship.git
synced 2026-06-23 02:05:51 +07: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:
committed by
Kevin Song
parent
80a9e7b9a6
commit
b050c59708
@@ -6,6 +6,7 @@ use std::fmt;
|
||||
|
||||
// List of all modules
|
||||
pub const ALL_MODULES: &[&str] = &[
|
||||
"aws",
|
||||
#[cfg(feature = "battery")]
|
||||
"battery",
|
||||
"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.
|
||||
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),
|
||||
|
||||
@@ -15,6 +15,7 @@ const DEFAULT_PROMPT_ORDER: &[&str] = &[
|
||||
"username",
|
||||
"hostname",
|
||||
"directory",
|
||||
"aws",
|
||||
"git_branch",
|
||||
"git_state",
|
||||
"git_status",
|
||||
|
||||
Reference in New Issue
Block a user