mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-28 15:56:28 +00:00
feat(java): Configure when the module is shown (#2353)
This makes it possible to configure when the java module is shown based on the contents of a directory.
This commit is contained in:
parent
c0a209f27c
commit
64288c2e04
@ -1362,7 +1362,7 @@ disabled = false
|
||||
## Java
|
||||
|
||||
The `java` module shows the currently installed version of Java.
|
||||
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 `pom.xml`, `build.gradle.kts`, `build.sbt`, `.java-version`, `.deps.edn`, `project.clj`, or `build.boot` file
|
||||
- The current directory contains a file with the `.java`, `.class`, `.gradle`, `.jar`, `.clj`, or `.cljc` extension
|
||||
@ -1370,8 +1370,11 @@ 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. |
|
||||
| `detect_extensions` | `["java", "class", "gradle", "jar", "cljs", "cljc"]` | Which extensions should trigger this module. |
|
||||
| `detect_files` | `["pom.xml", "build.gradle.kts", "build.sbt", ".java-version", ".deps.edn", "project.clj", "build.boot"]` | Which filenames should trigger this module. |
|
||||
| `detect_folders` | `[]` | Which folders should trigger this modules. |
|
||||
| `symbol` | `"☕ "` | A format string representing the symbol of Java |
|
||||
| `style` | `"red dimmed"` | The style for the module. |
|
||||
| `disabled` | `false` | Disables the `java` module. |
|
||||
|
@ -8,6 +8,9 @@ pub struct JavaConfig<'a> {
|
||||
pub format: &'a str,
|
||||
pub style: &'a str,
|
||||
pub symbol: &'a str,
|
||||
pub detect_extensions: Vec<&'a str>,
|
||||
pub detect_files: Vec<&'a str>,
|
||||
pub detect_folders: Vec<&'a str>,
|
||||
}
|
||||
|
||||
impl<'a> RootModuleConfig<'a> for JavaConfig<'a> {
|
||||
@ -17,6 +20,17 @@ impl<'a> RootModuleConfig<'a> for JavaConfig<'a> {
|
||||
disabled: false,
|
||||
style: "red dimmed",
|
||||
symbol: "☕ ",
|
||||
detect_extensions: vec!["java", "class", "jar", "gradle", "clj", "cljc"],
|
||||
detect_files: vec![
|
||||
"pom.xml",
|
||||
"build.gradle.kts",
|
||||
"build.sbt",
|
||||
".java-version",
|
||||
"deps.edn",
|
||||
"project.clj",
|
||||
"build.boot",
|
||||
],
|
||||
detect_folders: vec![],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,32 +7,21 @@ use regex::Regex;
|
||||
const JAVA_VERSION_PATTERN: &str = "(?P<version>[\\d\\.]+)[^\\s]*\\s(?:built|from)";
|
||||
|
||||
/// Creates a module with the current Java version
|
||||
///
|
||||
/// Will display the Java version if any of the following criteria are met:
|
||||
/// - Current directory contains a file with a `.java`, `.class`, `.jar`, `.gradle`, `.clj`, or `.cljc` extension
|
||||
/// - Current directory contains a `pom.xml`, `build.gradle.kts`, `build.sbt`, `.java-version`, `deps.edn`, `project.clj`, or `build.boot` file
|
||||
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
let mut module = context.new_module("java");
|
||||
let config: JavaConfig = JavaConfig::try_load(module.config);
|
||||
|
||||
let is_java_project = context
|
||||
.try_begin_scan()?
|
||||
.set_files(&[
|
||||
"pom.xml",
|
||||
"build.gradle.kts",
|
||||
"build.sbt",
|
||||
".java-version",
|
||||
"deps.edn",
|
||||
"project.clj",
|
||||
"build.boot",
|
||||
])
|
||||
.set_extensions(&["java", "class", "jar", "gradle", "clj", "cljc"])
|
||||
.set_files(&config.detect_files)
|
||||
.set_extensions(&config.detect_extensions)
|
||||
.set_folders(&config.detect_folders)
|
||||
.is_match();
|
||||
|
||||
if !is_java_project {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut module = context.new_module("java");
|
||||
let config: JavaConfig = JavaConfig::try_load(module.config);
|
||||
|
||||
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
|
||||
formatter
|
||||
.map_meta(|var, _| match var {
|
||||
|
Loading…
Reference in New Issue
Block a user