mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-25 06:07:43 +00: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
|
## Perl
|
||||||
|
|
||||||
The `perl` module shows the currently installed version of 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 `Makefile.PL` or `Build.PL` file
|
||||||
- The current directory contains a `cpanfile` or `cpanfile.snapshot` file
|
- The current directory contains a `cpanfile` or `cpanfile.snapshot` file
|
||||||
@ -1976,12 +1976,15 @@ The module will be shown if any of the following conditions are met:
|
|||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
| Option | Default | Description |
|
| Option | Default | Description |
|
||||||
| ---------- | ------------------------------------ | ----------------------------------------------------- |
|
| -------------------- | ------------------------------------ | ----------------------------------------------------- |
|
||||||
| `format` | `"via [$symbol($version )]($style)"` | The format string for the module. |
|
| `format` | `"via [$symbol($version )]($style)"` | The format string for the module. |
|
||||||
| `symbol` | `"🐪 "` | The symbol used before displaying the version of Perl |
|
| `symbol` | `"🐪 "` | The symbol used before displaying the version of Perl |
|
||||||
| `style` | `"bold 149"` | The style for the module. |
|
| `detect_extensions` | `["pl", "pm", "pod"]` | Which extensions should trigger this moudle. |
|
||||||
| `disabled` | `false` | Disables the `perl` module. |
|
| `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. |
|
||||||
|
|
||||||
### Variables
|
### Variables
|
||||||
|
|
||||||
|
@ -8,6 +8,9 @@ pub struct PerlConfig<'a> {
|
|||||||
pub style: &'a str,
|
pub style: &'a str,
|
||||||
pub format: &'a str,
|
pub format: &'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 PerlConfig<'a> {
|
impl<'a> RootModuleConfig<'a> for PerlConfig<'a> {
|
||||||
@ -17,6 +20,17 @@ impl<'a> RootModuleConfig<'a> for PerlConfig<'a> {
|
|||||||
style: "149 bold",
|
style: "149 bold",
|
||||||
format: "via [$symbol($version )]($style)",
|
format: "via [$symbol($version )]($style)",
|
||||||
disabled: false,
|
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;
|
use crate::formatter::StringFormatter;
|
||||||
|
|
||||||
/// Creates a module with the current perl version
|
/// 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>> {
|
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
|
let is_perl_project = context
|
||||||
.try_begin_scan()?
|
.try_begin_scan()?
|
||||||
.set_files(&[
|
.set_extensions(&config.detect_extensions)
|
||||||
"Makefile.PL",
|
.set_files(&config.detect_files)
|
||||||
"Build.PL",
|
.set_folders(&config.detect_folders)
|
||||||
"cpanfile",
|
|
||||||
"cpanfile.snapshot",
|
|
||||||
"META.json",
|
|
||||||
"META.yml",
|
|
||||||
".perl-version",
|
|
||||||
])
|
|
||||||
.set_extensions(&["pl", "pm", "pod"])
|
|
||||||
.is_match();
|
.is_match();
|
||||||
|
|
||||||
if !is_perl_project {
|
if !is_perl_project {
|
||||||
return None;
|
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| {
|
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
|
||||||
formatter
|
formatter
|
||||||
.map_meta(|var, _| match var {
|
.map_meta(|var, _| match var {
|
||||||
|
Loading…
Reference in New Issue
Block a user