mirror of
https://github.com/starship/starship.git
synced 2024-12-24 16:18:53 +01:00
feat(perl): Configure when the module is shown (#2355)
This makes it possible to configure when the perl 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
e73581ddf0
commit
51f752f6b0
@ -1966,7 +1966,7 @@ format = "via [🎁 $version](208 bold) "
|
||||
## Perl
|
||||
|
||||
The `perl` module shows the currently installed version of Perl.
|
||||
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 `Makefile.PL` or `Build.PL` file
|
||||
- The current directory contains a `cpanfile` or `cpanfile.snapshot` file
|
||||
@ -1977,9 +1977,12 @@ The module will be shown if any of the following conditions are met:
|
||||
### Options
|
||||
|
||||
| Option | Default | Description |
|
||||
| ---------- | ------------------------------------ | ----------------------------------------------------- |
|
||||
| -------------------- | ------------------------------------ | ----------------------------------------------------- |
|
||||
| `format` | `"via [$symbol($version )]($style)"` | The format string for the module. |
|
||||
| `symbol` | `"🐪 "` | The symbol used before displaying the version of Perl |
|
||||
| `detect_extensions` | `["pl", "pm", "pod"]` | Which extensions should trigger this moudle. |
|
||||
| `detect_files` | `["Makefile.PL", "Build.PL", "cpanfile", "cpanfile.snapshot", "META.json", "META.yml", ".perl-version"]` | Which filenames should trigger this module. |
|
||||
| `detect_folders` | `[]` | Which folders should trigger this module. |
|
||||
| `style` | `"bold 149"` | The style for the module. |
|
||||
| `disabled` | `false` | Disables the `perl` module. |
|
||||
|
||||
|
@ -8,6 +8,9 @@ pub struct PerlConfig<'a> {
|
||||
pub style: &'a str,
|
||||
pub format: &'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 PerlConfig<'a> {
|
||||
@ -17,6 +20,17 @@ impl<'a> RootModuleConfig<'a> for PerlConfig<'a> {
|
||||
style: "149 bold",
|
||||
format: "via [$symbol($version )]($style)",
|
||||
disabled: false,
|
||||
detect_extensions: vec!["pl", "pm", "pod"],
|
||||
detect_files: vec![
|
||||
"Makefile.PL",
|
||||
"Build.PL",
|
||||
"cpanfile",
|
||||
"cpanfile.snapshot",
|
||||
"META.json",
|
||||
"META.yml",
|
||||
".perl-version",
|
||||
],
|
||||
detect_folders: vec![],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,33 +4,20 @@ use crate::configs::perl::PerlConfig;
|
||||
use crate::formatter::StringFormatter;
|
||||
|
||||
/// Creates a module with the current perl version
|
||||
///
|
||||
/// Will display the perl version if any of the following criteria are met:
|
||||
/// - Current directory contains a `.pl`, `.pm` or a `.pod` file
|
||||
/// - Current directory contains a "Makefile.PL", "Build.PL", "cpanfile", "cpanfile.snapshot",
|
||||
/// "META.json", "META.yml", or ".perl-version" file
|
||||
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
let mut module = context.new_module("perl");
|
||||
let config: PerlConfig = PerlConfig::try_load(module.config);
|
||||
let is_perl_project = context
|
||||
.try_begin_scan()?
|
||||
.set_files(&[
|
||||
"Makefile.PL",
|
||||
"Build.PL",
|
||||
"cpanfile",
|
||||
"cpanfile.snapshot",
|
||||
"META.json",
|
||||
"META.yml",
|
||||
".perl-version",
|
||||
])
|
||||
.set_extensions(&["pl", "pm", "pod"])
|
||||
.set_extensions(&config.detect_extensions)
|
||||
.set_files(&config.detect_files)
|
||||
.set_folders(&config.detect_folders)
|
||||
.is_match();
|
||||
|
||||
if !is_perl_project {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut module = context.new_module("perl");
|
||||
let config: PerlConfig = PerlConfig::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