summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas O'Donnell <andytom@users.noreply.github.com>2021-02-20 18:32:04 +0100
committerGitHub <noreply@github.com>2021-02-20 18:32:04 +0100
commit9313e90773c8536e520bb34750345d7e4d4a6946 (patch)
tree7395ca5f67613f0cdf754e8bfdf7d7e3d8e22899
parent37d3425d219fef5e9de60ef29295f1bb7b57e94b (diff)
feat(elixir): Configure when module is shown (#2340)
This makes it possible to configure when the elixir module is shown based on the contents of a directory. This should make it possible to be a lot more granular when configuring the module.
-rw-r--r--docs/config/README.md37
-rw-r--r--src/configs/elixir.rs6
-rw-r--r--src/modules/elixir.rs15
3 files changed, 35 insertions, 23 deletions
diff --git a/docs/config/README.md b/docs/config/README.md
index f2438edd2..ab4c5e3d3 100644
--- a/docs/config/README.md
+++ b/docs/config/README.md
@@ -789,16 +789,16 @@ when there is a csproj file in the current directory.
### Options
-| Option | Default | Description |
-| ------------------- | -------------------------------------------------------------------------------------------------------- | -------------------------------------------------------- |
-| `format` | `"[$symbol($version )(🎯 $tfm )]($style)"` | The format for the module. |
-| `symbol` | `"•NET "` | The symbol used before displaying the version of dotnet. |
-| `heuristic` | `true` | Use faster version detection to keep starship snappy. |
-| `detect_extensions` | `["sln", "csproj", "fsproj", "xproj"]` | Which extensions should trigger this module. |
-| `detect_files` | `[ "global.json", "project.json", "Directory.Build.props", "Directory.Build.targets", "Packages.props"]` | Which filenames should trigger this module. |
-| `detect_folders` | `[]` | Which folders should trigger this modules. |
-| `style` | `"bold blue"` | The style for the module. |
-| `disabled` | `false` | Disables the `dotnet` module. |
+| Option | Default | Description |
+| ------------------- | ------------------------------------------------------------------------------------------------------- | -------------------------------------------------------- |
+| `format` | `"[$symbol($version )(🎯 $tfm )]($style)"` | The format for the module. |
+| `symbol` | `"•NET "` | The symbol used before displaying the version of dotnet. |
+| `heuristic` | `true` | Use faster version detection to keep starship snappy. |
+| `detect_extensions` | `["sln", "csproj", "fsproj", "xproj"]` | Which extensions should trigger this module. |
+| `detect_files` | `["global.json", "project.json", "Directory.Build.props", "Directory.Build.targets", "Packages.props"]` | Which filenames should trigger this module. |
+| `detect_folders` | `[]` | Which folders should trigger this modules. |
+| `style` | `"bold blue"` | The style for the module. |
+| `disabled` | `false` | Disables the `dotnet` module. |
### Variables
@@ -825,18 +825,21 @@ heuristic = false
## Elixir
The `elixir` module shows the currently installed version of Elixir and Erlang/OTP.
-The module will be shown if any of the following conditions are met:
+By default the module will be shown if any of the following conditions are met:
- The current directory contains a `mix.exs` file.
### Options
-| Option | Default | Description |
-| ---------- | --------------------------------------------------------- | --------------------------------------------------------------- |
-| `symbol` | `"💧 "` | The symbol used before displaying the version of Elixir/Erlang. |
-| `style` | `"bold purple"` | The style for the module. |
-| `format` | `'via [$symbol($version \(OTP $otp_version\) )]($style)'` | The format for the module elixir. |
-| `disabled` | `false` | Disables the `elixir` module. |
+| Option | Default | Description |
+| ------------------- | --------------------------------------------------------- | --------------------------------------------------------------- |
+| `symbol` | `"💧 "` | The symbol used before displaying the version of Elixir/Erlang. |
+| `detect_extensions` | `[]` | Which extensions should trigger this module. |
+| `detect_files` | `["mix.exs"]` | Which filenames should trigger this module. |
+| `detect_folders` | `[]` | Which folders should trigger this modules. |
+| `style` | `"bold purple"` | The style for the module. |
+| `format` | `'via [$symbol($version \(OTP $otp_version\) )]($style)'` | The format for the module elixir. |
+| `disabled` | `false` | Disables the `elixir` module. |
### Variables
diff --git a/src/configs/elixir.rs b/src/configs/elixir.rs
index ebe2a2711..254cdc542 100644
--- a/src/configs/elixir.rs
+++ b/src/configs/elixir.rs
@@ -8,6 +8,9 @@ pub struct ElixirConfig<'a> {
pub symbol: &'a str,
pub style: &'a str,
pub disabled: bool,
+ pub detect_extensions: Vec<&'a str>,
+ pub detect_files: Vec<&'a str>,
+ pub detect_folders: Vec<&'a str>,
}
impl<'a> RootModuleConfig<'a> for ElixirConfig<'a> {
@@ -17,6 +20,9 @@ impl<'a> RootModuleConfig<'a> for ElixirConfig<'a> {
symbol: "💧 ",
style: "bold purple",
disabled: false,
+ detect_extensions: vec![],
+ detect_files: vec!["mix.exs"],
+ detect_folders: vec![],
}
}
}
diff --git a/src/modules/elixir.rs b/src/modules/elixir.rs
index 22489b7c0..8d823655e 100644
--- a/src/modules/elixir.rs
+++ b/src/modules/elixir.rs
@@ -12,11 +12,16 @@ Erlang/OTP (?P<otp>\\d+)[^\\n]+
Elixir (?P<elixir>\\d[.\\d]+).*";
/// Create a module with the current Elixir version
-///
-/// Will display the Elixir version if any of the following criteria are met:
-/// - Current directory contains a `mix.exs` file
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
- let is_elixir_project = context.try_begin_scan()?.set_files(&["mix.exs"]).is_match();
+ let mut module = context.new_module("elixir");
+ let config = ElixirConfig::try_load(module.config);
+
+ let is_elixir_project = context
+ .try_begin_scan()?
+ .set_files(&config.detect_files)
+ .set_extensions(&config.detect_extensions)
+ .set_folders(&config.detect_folders)
+ .is_match();
if !is_elixir_project {
return None;
@@ -24,8 +29,6 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let versions = Lazy::new(|| get_elixir_version(context));
- let mut module = context.new_module("elixir");
- let config = ElixirConfig::try_load(module.config);
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
formatter
.map_meta(|var, _| match var {