mirror of
https://github.com/Llewellynvdm/starship.git
synced 2025-01-24 23:58:28 +00:00
feat(cmake): Configure when the module is shown (#2280)
This makes it possible to configure when the cmake 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.
This commit is contained in:
parent
eccbda8328
commit
47a769cdf8
@ -442,19 +442,23 @@ vicmd_symbol = "[V](bold green) "
|
|||||||
|
|
||||||
## CMake
|
## CMake
|
||||||
|
|
||||||
The `cmake` module shows the currently installed version of CMake if any of the following conditions are met:
|
The `cmake` module shows the currently installed version of CMake. By default
|
||||||
|
the module will be activated if any of the following conditions are met:
|
||||||
|
|
||||||
- The current directory contains a `CMakeLists.txt` file
|
- The current directory contains a `CMakeLists.txt` file
|
||||||
- The current directory contains a `CMakeCache.txt` file
|
- The current directory contains a `CMakeCache.txt` file
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
| Option | Default | Description |
|
| Option | Default | Description |
|
||||||
| ---------- | ------------------------------------ | -------------------------------------------- |
|
| ------------------- | -------------------------------------- | -------------------------------------------- |
|
||||||
| `format` | `"via [$symbol($version )]($style)"` | The format for the module. |
|
| `format` | `"via [$symbol($version )]($style)"` | The format for the module. |
|
||||||
| `symbol` | `"喝 "` | The symbol used before the version of cmake. |
|
| `symbol` | `"喝 "` | The symbol used before the version of cmake. |
|
||||||
| `style` | `"bold blue"` | The style for the module. |
|
| `detect_extensions` | `[]` | Which extensions should trigger this moudle |
|
||||||
| `disabled` | `false` | Disables the `cmake` module. |
|
| `detect_files` | `["CMakeLists.txt", "CMakeCache.txt"]` | Which filenames should trigger this module |
|
||||||
|
| `detect_folders` | `[]` | Which folders should trigger this module |
|
||||||
|
| `style` | `"bold blue"` | The style for the module. |
|
||||||
|
| `disabled` | `false` | Disables the `cmake` module. |
|
||||||
|
|
||||||
### Variables
|
### Variables
|
||||||
|
|
||||||
|
@ -8,6 +8,9 @@ pub struct CMakeConfig<'a> {
|
|||||||
pub symbol: &'a str,
|
pub symbol: &'a str,
|
||||||
pub style: &'a str,
|
pub style: &'a str,
|
||||||
pub disabled: bool,
|
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 CMakeConfig<'a> {
|
impl<'a> RootModuleConfig<'a> for CMakeConfig<'a> {
|
||||||
@ -17,6 +20,9 @@ impl<'a> RootModuleConfig<'a> for CMakeConfig<'a> {
|
|||||||
symbol: "喝 ",
|
symbol: "喝 ",
|
||||||
style: "bold blue",
|
style: "bold blue",
|
||||||
disabled: false,
|
disabled: false,
|
||||||
|
detect_extensions: vec![],
|
||||||
|
detect_files: vec!["CMakeLists.txt", "CMakeCache.txt"],
|
||||||
|
detect_folders: vec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,21 +4,21 @@ use crate::configs::cmake::CMakeConfig;
|
|||||||
use crate::formatter::StringFormatter;
|
use crate::formatter::StringFormatter;
|
||||||
|
|
||||||
/// Creates a module with the current CMake version
|
/// Creates a module with the current CMake version
|
||||||
///
|
|
||||||
/// Will display the CMake version if any of the following criteria are met:
|
|
||||||
/// - The current directory contains a `CMakeLists.txt` or `CMakeCache.txt`
|
|
||||||
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||||
|
let mut module = context.new_module("cmake");
|
||||||
|
let config = CMakeConfig::try_load(module.config);
|
||||||
|
|
||||||
let is_cmake_project = context
|
let is_cmake_project = context
|
||||||
.try_begin_scan()?
|
.try_begin_scan()?
|
||||||
.set_files(&["CMakeLists.txt", "CMakeCache.txt"])
|
.set_files(&config.detect_files)
|
||||||
|
.set_extensions(&config.detect_extensions)
|
||||||
|
.set_folders(&config.detect_folders)
|
||||||
.is_match();
|
.is_match();
|
||||||
|
|
||||||
if !is_cmake_project {
|
if !is_cmake_project {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut module = context.new_module("cmake");
|
|
||||||
let config = CMakeConfig::try_load(module.config);
|
|
||||||
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
|
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
|
||||||
formatter
|
formatter
|
||||||
.map_meta(|variable, _| match variable {
|
.map_meta(|variable, _| match variable {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user