diff --git a/docs/config/README.md b/docs/config/README.md index f2438edd..ab4c5e3d 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 ebe2a271..254cdc54 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 22489b7c..8d823655 100644 --- a/src/modules/elixir.rs +++ b/src/modules/elixir.rs @@ -12,11 +12,16 @@ Erlang/OTP (?P\\d+)[^\\n]+ Elixir (?P\\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> { - 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> { 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 {