2019-08-20 04:42:25 +00:00
|
|
|
// While adding out new module add out module to src/module.rs ALL_MODULES const array also.
|
2019-09-26 02:55:47 +00:00
|
|
|
mod aws;
|
2021-12-06 22:01:33 +00:00
|
|
|
mod azure;
|
2022-03-12 11:10:23 +00:00
|
|
|
mod buf;
|
2022-03-25 04:10:19 +00:00
|
|
|
mod c;
|
2019-04-05 01:35:24 +00:00
|
|
|
mod character;
|
2020-07-09 19:40:33 +00:00
|
|
|
mod cmake;
|
2019-08-08 17:25:30 +00:00
|
|
|
mod cmd_duration;
|
2021-09-07 14:59:14 +00:00
|
|
|
mod cobol;
|
2019-10-05 18:25:25 +00:00
|
|
|
mod conda;
|
2022-01-21 15:44:46 +00:00
|
|
|
mod container;
|
2020-02-04 23:27:06 +00:00
|
|
|
mod crystal;
|
2020-04-11 16:37:24 +00:00
|
|
|
pub(crate) mod custom;
|
2022-05-26 14:42:31 +00:00
|
|
|
mod daml;
|
2020-07-29 15:38:23 +00:00
|
|
|
mod dart;
|
2021-04-15 13:22:12 +00:00
|
|
|
mod deno;
|
2019-04-05 00:35:35 +00:00
|
|
|
mod directory;
|
2020-04-05 19:42:55 +00:00
|
|
|
mod docker_context;
|
2019-10-02 06:56:49 +00:00
|
|
|
mod dotnet;
|
2020-03-02 03:29:27 +00:00
|
|
|
mod elixir;
|
2020-02-06 03:57:04 +00:00
|
|
|
mod elm;
|
2019-09-26 08:30:58 +00:00
|
|
|
mod env_var;
|
2020-04-27 10:09:42 +00:00
|
|
|
mod erlang;
|
2021-09-12 23:59:15 +00:00
|
|
|
mod fill;
|
2020-08-03 21:30:20 +00:00
|
|
|
mod gcloud;
|
2019-04-27 02:07:07 +00:00
|
|
|
mod git_branch;
|
2019-12-06 16:57:42 +00:00
|
|
|
mod git_commit;
|
2021-07-10 20:54:34 +00:00
|
|
|
mod git_metrics;
|
2019-09-05 16:45:04 +00:00
|
|
|
mod git_state;
|
2019-05-14 04:43:11 +00:00
|
|
|
mod git_status;
|
2019-07-19 20:18:52 +00:00
|
|
|
mod golang;
|
2022-03-18 06:45:51 +00:00
|
|
|
mod haskell;
|
2020-07-17 07:51:25 +00:00
|
|
|
mod helm;
|
2019-12-02 22:37:18 +00:00
|
|
|
mod hg_branch;
|
2019-09-04 17:03:31 +00:00
|
|
|
mod hostname;
|
2019-09-19 23:02:53 +00:00
|
|
|
mod java;
|
2019-08-12 17:42:33 +00:00
|
|
|
mod jobs;
|
2020-04-03 18:16:34 +00:00
|
|
|
mod julia;
|
2020-12-26 14:26:50 +00:00
|
|
|
mod kotlin;
|
2019-10-01 18:58:24 +00:00
|
|
|
mod kubernetes;
|
2019-04-05 00:35:35 +00:00
|
|
|
mod line_break;
|
2022-01-30 20:31:26 +00:00
|
|
|
mod localip;
|
2020-10-27 18:05:20 +00:00
|
|
|
mod lua;
|
2019-09-29 05:55:49 +00:00
|
|
|
mod memory_usage;
|
2020-06-09 17:14:47 +00:00
|
|
|
mod nim;
|
2019-08-25 15:41:20 +00:00
|
|
|
mod nix_shell;
|
2019-04-10 13:22:11 +00:00
|
|
|
mod nodejs;
|
2020-05-21 16:43:13 +00:00
|
|
|
mod ocaml;
|
2020-10-24 09:46:43 +00:00
|
|
|
mod openstack;
|
2019-05-01 14:45:56 +00:00
|
|
|
mod package;
|
2020-08-04 16:22:44 +00:00
|
|
|
mod perl;
|
2019-12-05 18:04:27 +00:00
|
|
|
mod php;
|
2021-10-05 23:27:25 +00:00
|
|
|
mod pulumi;
|
2020-05-22 16:26:58 +00:00
|
|
|
mod purescript;
|
2019-04-25 15:06:18 +00:00
|
|
|
mod python;
|
2021-04-20 16:31:47 +00:00
|
|
|
mod red;
|
2021-05-25 18:13:30 +00:00
|
|
|
mod rlang;
|
2019-08-13 22:43:29 +00:00
|
|
|
mod ruby;
|
2019-04-21 23:37:34 +00:00
|
|
|
mod rust;
|
2021-03-14 19:37:00 +00:00
|
|
|
mod scala;
|
2021-02-20 14:40:49 +00:00
|
|
|
mod shell;
|
2020-08-05 16:30:01 +00:00
|
|
|
mod shlvl;
|
2020-02-26 16:18:19 +00:00
|
|
|
mod singularity;
|
2022-04-03 13:33:14 +00:00
|
|
|
mod spack;
|
2020-09-25 22:04:51 +00:00
|
|
|
mod status;
|
2021-11-15 05:46:13 +00:00
|
|
|
mod sudo;
|
2020-07-29 15:36:49 +00:00
|
|
|
mod swift;
|
2019-12-09 01:42:51 +00:00
|
|
|
mod terraform;
|
2019-09-10 17:54:40 +00:00
|
|
|
mod time;
|
2019-05-20 02:26:12 +00:00
|
|
|
mod username;
|
2019-10-25 01:00:05 +00:00
|
|
|
mod utils;
|
2021-01-30 11:05:16 +00:00
|
|
|
mod vagrant;
|
2021-03-28 15:48:15 +00:00
|
|
|
mod vcsh;
|
2021-05-03 19:50:29 +00:00
|
|
|
mod vlang;
|
2020-05-21 16:49:49 +00:00
|
|
|
mod zig;
|
2019-04-04 00:14:26 +00:00
|
|
|
|
2019-08-26 18:09:39 +00:00
|
|
|
#[cfg(feature = "battery")]
|
|
|
|
mod battery;
|
|
|
|
|
2021-06-29 23:46:41 +00:00
|
|
|
#[cfg(feature = "battery")]
|
2021-06-30 01:12:59 +00:00
|
|
|
pub use self::battery::{BatteryInfoProvider, BatteryInfoProviderImpl};
|
2021-06-29 23:46:41 +00:00
|
|
|
|
2022-03-26 09:42:19 +00:00
|
|
|
use crate::config::ModuleConfig;
|
2020-01-26 22:37:18 +00:00
|
|
|
use crate::context::{Context, Shell};
|
2019-05-01 20:34:24 +00:00
|
|
|
use crate::module::Module;
|
2020-09-21 17:06:15 +00:00
|
|
|
use std::time::Instant;
|
2019-04-04 16:18:02 +00:00
|
|
|
|
2019-06-10 14:56:17 +00:00
|
|
|
pub fn handle<'a>(module: &str, context: &'a Context) -> Option<Module<'a>> {
|
2020-09-21 17:06:15 +00:00
|
|
|
let start: Instant = Instant::now();
|
|
|
|
let mut m: Option<Module> = {
|
|
|
|
match module {
|
|
|
|
// Keep these ordered alphabetically.
|
|
|
|
// Default ordering is handled in configs/starship_root.rs
|
|
|
|
"aws" => aws::module(context),
|
2021-12-06 22:01:33 +00:00
|
|
|
"azure" => azure::module(context),
|
2020-09-21 17:06:15 +00:00
|
|
|
#[cfg(feature = "battery")]
|
|
|
|
"battery" => battery::module(context),
|
2022-03-12 11:10:23 +00:00
|
|
|
"buf" => buf::module(context),
|
2022-03-25 04:10:19 +00:00
|
|
|
"c" => c::module(context),
|
2020-09-21 17:06:15 +00:00
|
|
|
"character" => character::module(context),
|
|
|
|
"cmake" => cmake::module(context),
|
|
|
|
"cmd_duration" => cmd_duration::module(context),
|
2021-09-07 14:59:14 +00:00
|
|
|
"cobol" => cobol::module(context),
|
2020-09-21 17:06:15 +00:00
|
|
|
"conda" => conda::module(context),
|
2022-01-21 15:44:46 +00:00
|
|
|
"container" => container::module(context),
|
2022-05-26 14:42:31 +00:00
|
|
|
"daml" => daml::module(context),
|
2020-09-21 17:06:15 +00:00
|
|
|
"dart" => dart::module(context),
|
2021-04-15 13:22:12 +00:00
|
|
|
"deno" => deno::module(context),
|
2020-09-21 17:06:15 +00:00
|
|
|
"directory" => directory::module(context),
|
|
|
|
"docker_context" => docker_context::module(context),
|
|
|
|
"dotnet" => dotnet::module(context),
|
|
|
|
"elixir" => elixir::module(context),
|
|
|
|
"elm" => elm::module(context),
|
|
|
|
"erlang" => erlang::module(context),
|
|
|
|
"env_var" => env_var::module(context),
|
2021-09-12 23:59:15 +00:00
|
|
|
"fill" => fill::module(context),
|
2020-09-21 17:06:15 +00:00
|
|
|
"gcloud" => gcloud::module(context),
|
|
|
|
"git_branch" => git_branch::module(context),
|
|
|
|
"git_commit" => git_commit::module(context),
|
2021-07-10 20:54:34 +00:00
|
|
|
"git_metrics" => git_metrics::module(context),
|
2020-09-21 17:06:15 +00:00
|
|
|
"git_state" => git_state::module(context),
|
|
|
|
"git_status" => git_status::module(context),
|
|
|
|
"golang" => golang::module(context),
|
2022-03-18 06:45:51 +00:00
|
|
|
"haskell" => haskell::module(context),
|
2020-09-21 17:06:15 +00:00
|
|
|
"helm" => helm::module(context),
|
|
|
|
"hg_branch" => hg_branch::module(context),
|
|
|
|
"hostname" => hostname::module(context),
|
|
|
|
"java" => java::module(context),
|
|
|
|
"jobs" => jobs::module(context),
|
|
|
|
"julia" => julia::module(context),
|
2020-12-26 14:26:50 +00:00
|
|
|
"kotlin" => kotlin::module(context),
|
2020-09-21 17:06:15 +00:00
|
|
|
"kubernetes" => kubernetes::module(context),
|
|
|
|
"line_break" => line_break::module(context),
|
2022-01-30 20:31:26 +00:00
|
|
|
"localip" => localip::module(context),
|
2020-10-27 18:05:20 +00:00
|
|
|
"lua" => lua::module(context),
|
2020-09-21 17:06:15 +00:00
|
|
|
"memory_usage" => memory_usage::module(context),
|
|
|
|
"nim" => nim::module(context),
|
|
|
|
"nix_shell" => nix_shell::module(context),
|
|
|
|
"nodejs" => nodejs::module(context),
|
|
|
|
"ocaml" => ocaml::module(context),
|
2020-10-24 09:46:43 +00:00
|
|
|
"openstack" => openstack::module(context),
|
2020-09-21 17:06:15 +00:00
|
|
|
"package" => package::module(context),
|
|
|
|
"perl" => perl::module(context),
|
|
|
|
"php" => php::module(context),
|
2021-10-05 23:27:25 +00:00
|
|
|
"pulumi" => pulumi::module(context),
|
2020-09-21 17:06:15 +00:00
|
|
|
"purescript" => purescript::module(context),
|
|
|
|
"python" => python::module(context),
|
2021-05-25 18:13:30 +00:00
|
|
|
"rlang" => rlang::module(context),
|
2021-04-20 16:31:47 +00:00
|
|
|
"red" => red::module(context),
|
2020-09-21 17:06:15 +00:00
|
|
|
"ruby" => ruby::module(context),
|
|
|
|
"rust" => rust::module(context),
|
2021-03-14 19:37:00 +00:00
|
|
|
"scala" => scala::module(context),
|
2021-02-20 14:40:49 +00:00
|
|
|
"shell" => shell::module(context),
|
2020-09-21 17:06:15 +00:00
|
|
|
"shlvl" => shlvl::module(context),
|
|
|
|
"singularity" => singularity::module(context),
|
2022-04-03 13:33:14 +00:00
|
|
|
"spack" => spack::module(context),
|
2020-09-21 17:06:15 +00:00
|
|
|
"swift" => swift::module(context),
|
2020-09-25 22:04:51 +00:00
|
|
|
"status" => status::module(context),
|
2021-11-15 05:46:13 +00:00
|
|
|
"sudo" => sudo::module(context),
|
2020-09-21 17:06:15 +00:00
|
|
|
"terraform" => terraform::module(context),
|
|
|
|
"time" => time::module(context),
|
|
|
|
"crystal" => crystal::module(context),
|
|
|
|
"username" => username::module(context),
|
2021-05-03 19:50:29 +00:00
|
|
|
"vlang" => vlang::module(context),
|
2021-01-30 11:05:16 +00:00
|
|
|
"vagrant" => vagrant::module(context),
|
2021-03-28 15:48:15 +00:00
|
|
|
"vcsh" => vcsh::module(context),
|
2020-09-21 17:06:15 +00:00
|
|
|
"zig" => zig::module(context),
|
2022-04-09 15:32:45 +00:00
|
|
|
// Added for tests, avoid potential side effects in production code.
|
|
|
|
#[cfg(test)]
|
|
|
|
custom if custom.starts_with("custom.") => {
|
|
|
|
// SAFETY: We just checked that the module starts with "custom."
|
|
|
|
custom::module(custom.strip_prefix("custom.").unwrap(), context)
|
|
|
|
}
|
2020-09-21 17:06:15 +00:00
|
|
|
_ => {
|
|
|
|
eprintln!("Error: Unknown module {}. Use starship module --list to list out all supported modules.", module);
|
|
|
|
None
|
|
|
|
}
|
2019-08-20 04:42:25 +00:00
|
|
|
}
|
2020-09-21 17:06:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let elapsed = start.elapsed();
|
|
|
|
log::trace!("Took {:?} to compute module {:?}", elapsed, module);
|
2021-06-16 19:23:14 +00:00
|
|
|
if elapsed.as_millis() >= 1 {
|
2020-09-21 17:06:15 +00:00
|
|
|
// If we take less than 1ms to compute a None, then we will not return a module at all
|
|
|
|
// if we have a module: default duration is 0 so no need to change it
|
|
|
|
// if we took more than 1ms we want to report that and so--in case we have None currently--
|
|
|
|
// need to create an empty module just to hold the duration for that case
|
|
|
|
m.get_or_insert_with(|| context.new_module(module)).duration = elapsed;
|
2019-04-04 00:14:26 +00:00
|
|
|
}
|
2021-06-16 19:23:14 +00:00
|
|
|
m
|
2019-04-04 00:14:26 +00:00
|
|
|
}
|
2020-01-02 04:19:08 +00:00
|
|
|
|
|
|
|
pub fn description(module: &str) -> &'static str {
|
|
|
|
match module {
|
|
|
|
"aws" => "The current AWS region and profile",
|
2021-12-06 22:01:33 +00:00
|
|
|
"azure" => "The current Azure subscription",
|
2020-01-02 04:19:08 +00:00
|
|
|
"battery" => "The current charge of the device's battery and its current charging status",
|
2022-03-12 11:10:23 +00:00
|
|
|
"buf" => "The currently installed version of the Buf CLI",
|
2022-03-25 04:10:19 +00:00
|
|
|
"c" => "Your C compiler type",
|
2020-01-02 04:19:08 +00:00
|
|
|
"character" => {
|
|
|
|
"A character (usually an arrow) beside where the text is entered in your terminal"
|
|
|
|
}
|
2020-07-09 19:40:33 +00:00
|
|
|
"cmake" => "The currently installed version of CMake",
|
2020-01-02 04:19:08 +00:00
|
|
|
"cmd_duration" => "How long the last command took to execute",
|
2021-09-07 14:59:14 +00:00
|
|
|
"cobol" => "The currently installed version of COBOL/GNUCOBOL",
|
2020-01-02 04:19:08 +00:00
|
|
|
"conda" => "The current conda environment, if $CONDA_DEFAULT_ENV is set",
|
2022-01-21 15:44:46 +00:00
|
|
|
"container" => "The container indicator, if inside a container.",
|
2020-04-24 17:37:34 +00:00
|
|
|
"crystal" => "The currently installed version of Crystal",
|
2022-05-26 14:42:31 +00:00
|
|
|
"daml" => "The Daml SDK version of your project",
|
2020-07-29 15:38:23 +00:00
|
|
|
"dart" => "The currently installed version of Dart",
|
2021-04-15 13:22:12 +00:00
|
|
|
"deno" => "The currently installed version of Deno",
|
2020-01-02 04:19:08 +00:00
|
|
|
"directory" => "The current working directory",
|
2020-04-05 19:42:55 +00:00
|
|
|
"docker_context" => "The current docker context",
|
2020-01-02 04:19:08 +00:00
|
|
|
"dotnet" => "The relevant version of the .NET Core SDK for the current directory",
|
2021-09-17 21:16:02 +00:00
|
|
|
"elixir" => "The currently installed versions of Elixir and OTP",
|
|
|
|
"elm" => "The currently installed version of Elm",
|
2020-01-02 04:19:08 +00:00
|
|
|
"env_var" => "Displays the current value of a selected environment variable",
|
2020-04-27 10:09:42 +00:00
|
|
|
"erlang" => "Current OTP version",
|
2021-09-12 23:59:15 +00:00
|
|
|
"fill" => "Fills the remaining space on the line with a pad string",
|
2020-08-03 21:30:20 +00:00
|
|
|
"gcloud" => "The current GCP client configuration",
|
2020-01-02 04:19:08 +00:00
|
|
|
"git_branch" => "The active branch of the repo in your current directory",
|
2020-10-23 15:49:19 +00:00
|
|
|
"git_commit" => "The active commit (and tag if any) of the repo in your current directory",
|
2021-07-10 20:54:34 +00:00
|
|
|
"git_metrics" => "The currently added/deleted lines in your repo",
|
2020-01-02 04:19:08 +00:00
|
|
|
"git_state" => "The current git operation, and it's progress",
|
|
|
|
"git_status" => "Symbol representing the state of the repo",
|
|
|
|
"golang" => "The currently installed version of Golang",
|
2022-03-18 06:45:51 +00:00
|
|
|
"haskell" => "The selected version of the Haskell toolchain",
|
2020-07-17 07:51:25 +00:00
|
|
|
"helm" => "The currently installed version of Helm",
|
2020-01-02 04:19:08 +00:00
|
|
|
"hg_branch" => "The active branch of the repo in your current directory",
|
|
|
|
"hostname" => "The system hostname",
|
|
|
|
"java" => "The currently installed version of Java",
|
|
|
|
"jobs" => "The current number of jobs running",
|
2020-04-03 18:16:34 +00:00
|
|
|
"julia" => "The currently installed version of Julia",
|
2020-12-26 14:26:50 +00:00
|
|
|
"kotlin" => "The currently installed version of Kotlin",
|
2020-01-02 04:19:08 +00:00
|
|
|
"kubernetes" => "The current Kubernetes context name and, if set, the namespace",
|
|
|
|
"line_break" => "Separates the prompt into two lines",
|
2022-01-30 20:31:26 +00:00
|
|
|
"localip" => "The currently assigned ipv4 address",
|
2020-10-27 18:05:20 +00:00
|
|
|
"lua" => "The currently installed version of Lua",
|
2020-01-02 04:19:08 +00:00
|
|
|
"memory_usage" => "Current system memory and swap usage",
|
2020-06-09 17:14:47 +00:00
|
|
|
"nim" => "The currently installed version of Nim",
|
2020-01-02 04:19:08 +00:00
|
|
|
"nix_shell" => "The nix-shell environment",
|
|
|
|
"nodejs" => "The currently installed version of NodeJS",
|
2020-05-21 16:43:13 +00:00
|
|
|
"ocaml" => "The currently installed version of OCaml",
|
2020-10-24 09:46:43 +00:00
|
|
|
"openstack" => "The current OpenStack cloud and project",
|
2020-01-02 04:19:08 +00:00
|
|
|
"package" => "The package version of the current directory's project",
|
2020-08-04 16:22:44 +00:00
|
|
|
"perl" => "The currently installed version of Perl",
|
2020-01-02 04:19:08 +00:00
|
|
|
"php" => "The currently installed version of PHP",
|
2022-01-25 16:40:44 +00:00
|
|
|
"pulumi" => "The current username, stack, and installed version of Pulumi",
|
2020-05-22 16:26:58 +00:00
|
|
|
"purescript" => "The currently installed version of PureScript",
|
2020-01-02 04:19:08 +00:00
|
|
|
"python" => "The currently installed version of Python",
|
2021-04-20 16:31:47 +00:00
|
|
|
"red" => "The currently installed version of Red",
|
2021-09-17 21:16:02 +00:00
|
|
|
"rlang" => "The currently installed version of R",
|
2020-01-02 04:19:08 +00:00
|
|
|
"ruby" => "The currently installed version of Ruby",
|
|
|
|
"rust" => "The currently installed version of Rust",
|
2021-03-14 19:37:00 +00:00
|
|
|
"scala" => "The currently installed version of Scala",
|
2021-02-20 14:40:49 +00:00
|
|
|
"shell" => "The currently used shell indicator",
|
2020-08-05 16:30:01 +00:00
|
|
|
"shlvl" => "The current value of SHLVL",
|
2021-09-17 21:16:02 +00:00
|
|
|
"singularity" => "The currently used Singularity image",
|
2022-04-03 13:33:14 +00:00
|
|
|
"spack" => "The current spack environment, if $SPACK_ENV is set",
|
2020-09-25 22:04:51 +00:00
|
|
|
"status" => "The status of the last command",
|
2021-11-15 05:46:13 +00:00
|
|
|
"sudo" => "The sudo credentials are currently cached",
|
2021-09-17 21:16:02 +00:00
|
|
|
"swift" => "The currently installed version of Swift",
|
2020-01-02 04:19:08 +00:00
|
|
|
"terraform" => "The currently selected terraform workspace and version",
|
|
|
|
"time" => "The current local time",
|
|
|
|
"username" => "The active user's username",
|
2021-01-30 11:05:16 +00:00
|
|
|
"vagrant" => "The currently installed version of Vagrant",
|
2021-03-28 15:48:15 +00:00
|
|
|
"vcsh" => "The currently active VCSH repository",
|
2021-09-17 21:16:02 +00:00
|
|
|
"vlang" => "The currently installed version of V",
|
2020-05-21 16:49:49 +00:00
|
|
|
"zig" => "The currently installed version of Zig",
|
2020-01-02 04:19:08 +00:00
|
|
|
_ => "<no description>",
|
|
|
|
}
|
|
|
|
}
|
2021-09-17 21:16:02 +00:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
|
|
|
use super::*;
|
|
|
|
use crate::module::ALL_MODULES;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn all_modules_have_description() {
|
|
|
|
for module in ALL_MODULES {
|
|
|
|
println!("Checking if {:?} has a description", module);
|
|
|
|
assert_ne!(description(module), "<no description>");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|