diff --git a/docs/config/README.md b/docs/config/README.md index 1249fa03..80da0404 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -1569,7 +1569,7 @@ disabled = true ## Lua The `lua` module shows the currently installed version of Lua. -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 `.lua-version` file - The current directory contains a `lua` directory @@ -1577,13 +1577,16 @@ The module will be shown if any of the following conditions are met: ### Options -| Option | Default | Description | -| ------------ | ------------------------------------ | ----------------------------------------------------------------------------- | -| `format` | `"via [$symbol($version )]($style)"` | The format for the module. | -| `symbol` | `"🌙 "` | A format string representing the symbol of Lua. | -| `style` | `"bold blue"` | The style for the module. | -| `lua_binary` | `"lua"` | Configures the lua binary that Starship executes when getting the version. | -| `disabled` | `false` | Disables the `lua` module. | +| Option | Default | Description | +| ------------------- | ------------------------------------ | ----------------------------------------------------------------------------- | +| `format` | `"via [$symbol($version )]($style)"` | The format for the module. | +| `symbol` | `"🌙 "` | A format string representing the symbol of Lua. | +| `detect_extensions` | `["lua"]` | Which extensions should trigger this moudle. | +| `detect_files` | `[".lua-version"]` | Which filenames should trigger this module. | +| `detect_folders` | `["lua"]` | Which folders should trigger this module. | +| `style` | `"bold blue"` | The style for the module. | +| `lua_binary` | `"lua"` | Configures the lua binary that Starship executes when getting the version. | +| `disabled` | `false` | Disables the `lua` module. | ### Variables diff --git a/src/configs/lua.rs b/src/configs/lua.rs index 6ba8593f..38abac8e 100644 --- a/src/configs/lua.rs +++ b/src/configs/lua.rs @@ -9,6 +9,9 @@ pub struct LuaConfig<'a> { pub style: &'a str, pub lua_binary: &'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 LuaConfig<'a> { @@ -19,6 +22,9 @@ impl<'a> RootModuleConfig<'a> for LuaConfig<'a> { style: "bold blue", lua_binary: "lua", disabled: false, + detect_extensions: vec!["lua"], + detect_files: vec![".lua-version"], + detect_folders: vec!["lua"], } } } diff --git a/src/modules/lua.rs b/src/modules/lua.rs index 8c7aa556..66219e9d 100644 --- a/src/modules/lua.rs +++ b/src/modules/lua.rs @@ -7,25 +7,21 @@ use regex::Regex; const LUA_VERSION_PATERN: &str = "(?P[\\d\\.]+[a-z\\-]*[1-9]*)[^\\s]*"; /// Creates a module with the current Lua version -/// -/// Will display the Lua version if any of the following criteria are met: -/// - Current directory contains a `.lua-version` file -/// - Current directory contains a `lua` directory -/// - Current directory contains a file with the `.lua` extension pub fn module<'a>(context: &'a Context) -> Option> { + let mut module = context.new_module("lua"); + let config = LuaConfig::try_load(module.config); + let is_lua_project = context .try_begin_scan()? - .set_files(&[".lua-version"]) - .set_folders(&["lua"]) - .set_extensions(&["lua"]) + .set_files(&config.detect_files) + .set_folders(&config.detect_folders) + .set_extensions(&config.detect_extensions) .is_match(); if !is_lua_project { return None; } - let mut module = context.new_module("lua"); - let config = LuaConfig::try_load(module.config); let parsed = StringFormatter::new(config.format).and_then(|formatter| { formatter .map_meta(|var, _| match var {