mirror of
https://github.com/starship/starship.git
synced 2025-01-07 06:58:54 +01:00
Merge branch 'master' into conditional-style
This commit is contained in:
commit
337c6ee7a0
35
.github/config-schema.json
vendored
35
.github/config-schema.json
vendored
@ -627,6 +627,19 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"guix_shell": {
|
||||
"default": {
|
||||
"disabled": false,
|
||||
"format": "via [$symbol]($style) ",
|
||||
"style": "yellow bold",
|
||||
"symbol": "🐃 "
|
||||
},
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/GuixShellConfig"
|
||||
}
|
||||
]
|
||||
},
|
||||
"haskell": {
|
||||
"default": {
|
||||
"detect_extensions": [
|
||||
@ -3173,6 +3186,28 @@
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"GuixShellConfig": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"format": {
|
||||
"default": "via [$symbol]($style) ",
|
||||
"type": "string"
|
||||
},
|
||||
"symbol": {
|
||||
"default": "🐃 ",
|
||||
"type": "string"
|
||||
},
|
||||
"style": {
|
||||
"default": "yellow bold",
|
||||
"type": "string"
|
||||
},
|
||||
"disabled": {
|
||||
"default": false,
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
},
|
||||
"HaskellConfig": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
2
.github/workflows/format-workflow.yml
vendored
2
.github/workflows/format-workflow.yml
vendored
@ -24,7 +24,7 @@ jobs:
|
||||
- name: Setup | Checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: Install | Taplo
|
||||
run: cargo install --debug --locked --version 0.7.0 taplo-cli
|
||||
run: cargo install --debug --locked --version 0.7.2 taplo-cli
|
||||
- name: Presets | Validate with schema
|
||||
run: taplo lint --schema "file://${GITHUB_WORKSPACE}/.github/config-schema.json" docs/.vuepress/public/presets/toml/*.toml
|
||||
|
||||
|
16
Cargo.lock
generated
16
Cargo.lock
generated
@ -2251,9 +2251,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "quick-xml"
|
||||
version = "0.25.0"
|
||||
version = "0.26.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "58e21a144a0ffb5fad7b464babcdab934a325ad69b7c0373bcfef5cbd9799ca9"
|
||||
checksum = "7f50b1c63b38611e7d4d7f68b82d3ad0cc71a2ad2e7f61fc10f1328d917c93cd"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
@ -2639,9 +2639,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "shadow-rs"
|
||||
version = "0.17.0"
|
||||
version = "0.17.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a645481cceb2b3975778f76c3c5e83af919e27b22dfc93d14f697a68d1210217"
|
||||
checksum = "f679e51942d1dbd5a7ebfb442d30855fa951152512176bb21f5f55ed0fd2f53b"
|
||||
dependencies = [
|
||||
"const_format",
|
||||
"is_debug",
|
||||
@ -2762,7 +2762,7 @@ dependencies = [
|
||||
"pest",
|
||||
"pest_derive",
|
||||
"process_control",
|
||||
"quick-xml 0.25.0",
|
||||
"quick-xml 0.26.0",
|
||||
"rand 0.8.5",
|
||||
"rayon",
|
||||
"regex",
|
||||
@ -2786,7 +2786,7 @@ dependencies = [
|
||||
"urlencoding",
|
||||
"versions",
|
||||
"which",
|
||||
"windows 0.42.0",
|
||||
"windows 0.43.0",
|
||||
"winres",
|
||||
"yaml-rust",
|
||||
]
|
||||
@ -3420,9 +3420,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "windows"
|
||||
version = "0.42.0"
|
||||
version = "0.43.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0286ba339aa753e70765d521bb0242cc48e1194562bfa2a2ad7ac8a6de28f5d5"
|
||||
checksum = "04662ed0e3e5630dfa9b26e4cb823b817f1a9addda855d973a9458c236556244"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm 0.42.0",
|
||||
"windows_aarch64_msvc 0.42.0",
|
||||
|
@ -64,7 +64,7 @@ os_info = "3.5.1"
|
||||
path-slash = "0.2.1"
|
||||
pest = "2.4.0"
|
||||
pest_derive = "2.4.0"
|
||||
quick-xml = "0.25.0"
|
||||
quick-xml = "0.26.0"
|
||||
rand = "0.8.5"
|
||||
rayon = "1.5.3"
|
||||
regex = "1.6.0"
|
||||
@ -73,7 +73,7 @@ semver = "1.0.14"
|
||||
serde = { version = "1.0.147", features = ["derive"] }
|
||||
serde_json = "1.0.87"
|
||||
sha-1 = "0.10.0"
|
||||
shadow-rs = { version = "0.17.0", default-features = false }
|
||||
shadow-rs = { version = "0.17.1", default-features = false }
|
||||
# battery is optional (on by default) because the crate doesn't currently build for Termux
|
||||
# see: https://github.com/svartalf/rust-battery/issues/33
|
||||
starship-battery = { version = "0.7.9", optional = true }
|
||||
@ -104,7 +104,7 @@ features = ["preserve_order", "indexmap"]
|
||||
deelevate = "0.2.0"
|
||||
|
||||
[target.'cfg(windows)'.dependencies.windows]
|
||||
version = "0.42.0"
|
||||
version = "0.43.0"
|
||||
features = [
|
||||
"Win32_Foundation",
|
||||
"Win32_UI_Shell",
|
||||
@ -117,7 +117,7 @@ features = [
|
||||
nix = { version = "0.25.0", default-features = false, features = ["feature", "fs", "user"] }
|
||||
|
||||
[build-dependencies]
|
||||
shadow-rs = { version = "0.17.0", default-features = false }
|
||||
shadow-rs = { version = "0.17.1", default-features = false }
|
||||
dunce = "1.0.3"
|
||||
|
||||
[target.'cfg(windows)'.build-dependencies]
|
||||
|
@ -58,6 +58,9 @@ format = '([\[$all_status$ahead_behind\]]($style))'
|
||||
[golang]
|
||||
format = '\[[$symbol($version)]($style)\]'
|
||||
|
||||
[guix_shell]
|
||||
format = '\[[$symbol]($style)\]'
|
||||
|
||||
[haskell]
|
||||
format = '\[[$symbol($version)]($style)\]'
|
||||
|
||||
|
@ -31,6 +31,9 @@ symbol = " "
|
||||
[golang]
|
||||
symbol = " "
|
||||
|
||||
[guix_shell]
|
||||
symbol = " "
|
||||
|
||||
[haskell]
|
||||
symbol = " "
|
||||
|
||||
|
@ -64,6 +64,9 @@ symbol = "git "
|
||||
[golang]
|
||||
symbol = "go "
|
||||
|
||||
[guix_shell]
|
||||
symbol = "guix "
|
||||
|
||||
[hg_branch]
|
||||
symbol = "hg "
|
||||
|
||||
|
@ -250,6 +250,7 @@ $elixir\
|
||||
$elm\
|
||||
$erlang\
|
||||
$golang\
|
||||
$guix_shell\
|
||||
$haskell\
|
||||
$helm\
|
||||
$java\
|
||||
@ -337,8 +338,8 @@ falls back to the `x_security_token_expires` key.
|
||||
| ------------------- | ----------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
|
||||
| `format` | `'on [$symbol($profile )(\($region\) )(\[$duration\] )]($style)'` | The format for the module. |
|
||||
| `symbol` | `"☁️ "` | The symbol used before displaying the current AWS profile. |
|
||||
| `region_aliases` | | Table of region aliases to display in addition to the AWS name. |
|
||||
| `profile_aliases` | | Table of profile aliases to display in addition to the AWS name. |
|
||||
| `region_aliases` | `{}` | Table of region aliases to display in addition to the AWS name. |
|
||||
| `profile_aliases` | `{}` | Table of profile aliases to display in addition to the AWS name. |
|
||||
| `style` | `"bold yellow"` | The style for the module. |
|
||||
| `expiration_symbol` | `X` | The symbol displayed when the temporary credentials have expired. |
|
||||
| `disabled` | `false` | Disables the `AWS` module. |
|
||||
@ -1464,8 +1465,8 @@ This is based on the `~/.config/gcloud/active_config` file and the `~/.config/gc
|
||||
| ----------------- | -------------------------------------------------------- | ---------------------------------------------------------------- |
|
||||
| `format` | `'on [$symbol$account(@$domain)(\($region\))]($style) '` | The format for the module. |
|
||||
| `symbol` | `"☁️ "` | The symbol used before displaying the current GCP profile. |
|
||||
| `region_aliases` | | Table of region aliases to display in addition to the GCP name. |
|
||||
| `project_aliases` | | Table of project aliases to display in addition to the GCP name. |
|
||||
| `region_aliases` | `{}` | Table of region aliases to display in addition to the GCP name. |
|
||||
| `project_aliases` | `{}` | Table of project aliases to display in addition to the GCP name. |
|
||||
| `style` | `"bold blue"` | The style for the module. |
|
||||
| `disabled` | `false` | Disables the `gcloud` module. |
|
||||
|
||||
@ -1842,6 +1843,39 @@ By default the module will be shown if any of the following conditions are met:
|
||||
format = "via [🏎💨 $version](bold cyan) "
|
||||
```
|
||||
|
||||
## Guix-shell
|
||||
|
||||
The `guix_shell` module shows the [guix-shell](https://guix.gnu.org/manual/devel/en/html_node/Invoking-guix-shell.html) environment.
|
||||
The module will be shown when inside a guix-shell environment.
|
||||
|
||||
### Options
|
||||
|
||||
| Option | Default | Description |
|
||||
| ---------- | -------------------------- | ------------------------------------------------------ |
|
||||
| `format` | `'via [$symbol]($style) '` | The format for the module. |
|
||||
| `symbol` | `"🐃 "` | A format string representing the symbol of guix-shell. |
|
||||
| `style` | `"yellow bold"` | The style for the module. |
|
||||
| `disabled` | `false` | Disables the `guix_shell` module. |
|
||||
|
||||
### Variables
|
||||
|
||||
| Variable | Example | Description |
|
||||
| -------- | ------- | ------------------------------------ |
|
||||
| symbol | | Mirrors the value of option `symbol` |
|
||||
| style\* | | Mirrors the value of option `style` |
|
||||
|
||||
*: This variable can only be used as a part of a style string
|
||||
|
||||
### Example
|
||||
|
||||
```toml
|
||||
# ~/.config/starship.toml
|
||||
|
||||
[guix_shell]
|
||||
disabled = true
|
||||
format = 'via [🐂](yellow bold) '
|
||||
```
|
||||
|
||||
## Haskell
|
||||
|
||||
The `haskell` module finds the current selected GHC version and/or the selected Stack snapshot.
|
||||
@ -2174,8 +2208,8 @@ case the module will only be active in directories that match those conditions.
|
||||
| `symbol` | `"☸ "` | A format string representing the symbol displayed before the Cluster. |
|
||||
| `format` | `'[$symbol$context( \($namespace\))]($style) in '` | The format for the module. |
|
||||
| `style` | `"cyan bold"` | The style for the module. |
|
||||
| `context_aliases` | | Table of context aliases to display. |
|
||||
| `user_aliases` | | Table of user aliases to display. |
|
||||
| `context_aliases` | `{}` | Table of context aliases to display. |
|
||||
| `user_aliases` | `{}` | Table of user aliases to display. |
|
||||
| `detect_extensions` | `[]` | Which extensions should trigger this module. |
|
||||
| `detect_files` | `[]` | Which filenames should trigger this module. |
|
||||
| `detect_folders` | `[]` | Which folders should trigger this modules. |
|
||||
@ -3330,7 +3364,7 @@ To enable it, set `disabled` to `false` in your configuration file.
|
||||
| `xonsh_indicator` | `"xsh"` | A format string used to represent xonsh. |
|
||||
| `cmd_indicator` | `"cmd"` | A format string used to represent cmd. |
|
||||
| `nu_indicator` | `"nu"` | A format string used to represent nu. |
|
||||
| `unknown_indicator` | | The default value to be displayed when the shell is unknown. |
|
||||
| `unknown_indicator` | `""` | The default value to be displayed when the shell is unknown. |
|
||||
| `format` | `"[$indicator]($style) "` | The format for the module. |
|
||||
| `style` | `"white bold"` | The style for the module. |
|
||||
| `disabled` | `true` | Disables the `shell` module. |
|
||||
@ -3857,7 +3891,7 @@ The module will be shown only if a repository is currently in use.
|
||||
|
||||
| Option | Default | Description |
|
||||
| ---------- | -------------------------------- | ------------------------------------------------------ |
|
||||
| `symbol` | | The symbol used before displaying the repository name. |
|
||||
| `symbol` | `""` | The symbol used before displaying the repository name. |
|
||||
| `style` | `"bold yellow"` | The style for the module. |
|
||||
| `format` | `"vcsh [$symbol$repo]($style) "` | The format for the module. |
|
||||
| `disabled` | `false` | Disables the `vcsh` module. |
|
||||
|
26
src/configs/guix_shell.rs
Normal file
26
src/configs/guix_shell.rs
Normal file
@ -0,0 +1,26 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Deserialize, Serialize)]
|
||||
#[cfg_attr(
|
||||
feature = "config-schema",
|
||||
derive(schemars::JsonSchema),
|
||||
schemars(deny_unknown_fields)
|
||||
)]
|
||||
#[serde(default)]
|
||||
pub struct GuixShellConfig<'a> {
|
||||
pub format: &'a str,
|
||||
pub symbol: &'a str,
|
||||
pub style: &'a str,
|
||||
pub disabled: bool,
|
||||
}
|
||||
|
||||
impl<'a> Default for GuixShellConfig<'a> {
|
||||
fn default() -> Self {
|
||||
GuixShellConfig {
|
||||
format: "via [$symbol]($style) ",
|
||||
symbol: "🐃 ",
|
||||
style: "yellow bold",
|
||||
disabled: false,
|
||||
}
|
||||
}
|
||||
}
|
@ -33,6 +33,7 @@ pub mod git_metrics;
|
||||
pub mod git_state;
|
||||
pub mod git_status;
|
||||
pub mod go;
|
||||
pub mod guix_shell;
|
||||
pub mod haskell;
|
||||
pub mod helm;
|
||||
pub mod hg_branch;
|
||||
@ -161,6 +162,8 @@ pub struct FullConfig<'a> {
|
||||
#[serde(borrow)]
|
||||
golang: go::GoConfig<'a>,
|
||||
#[serde(borrow)]
|
||||
guix_shell: guix_shell::GuixShellConfig<'a>,
|
||||
#[serde(borrow)]
|
||||
haskell: haskell::HaskellConfig<'a>,
|
||||
#[serde(borrow)]
|
||||
helm: helm::HelmConfig<'a>,
|
||||
|
@ -86,6 +86,7 @@ pub const PROMPT_ORDER: &[&str] = &[
|
||||
"zig",
|
||||
// ↑ Toolchain version modules ↑
|
||||
"buf",
|
||||
"guix_shell",
|
||||
"nix_shell",
|
||||
"conda",
|
||||
"meson",
|
||||
|
@ -8,7 +8,7 @@ let-env PROMPT_INDICATOR = ""
|
||||
|
||||
let-env PROMPT_COMMAND = {
|
||||
# jobs are not supported
|
||||
let width = (term size | get columns | into string)
|
||||
let width = (term size).columns
|
||||
^::STARSHIP:: prompt $"--cmd-duration=($env.CMD_DURATION_MS)" $"--status=($env.LAST_EXIT_CODE)" $"--terminal-width=($width)"
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,7 @@ pub const ALL_MODULES: &[&str] = &[
|
||||
"git_state",
|
||||
"git_status",
|
||||
"golang",
|
||||
"guix_shell",
|
||||
"haskell",
|
||||
"helm",
|
||||
"hg_branch",
|
||||
|
69
src/modules/guix_shell.rs
Normal file
69
src/modules/guix_shell.rs
Normal file
@ -0,0 +1,69 @@
|
||||
use super::{Context, Module, ModuleConfig};
|
||||
|
||||
use crate::configs::guix_shell::GuixShellConfig;
|
||||
use crate::formatter::StringFormatter;
|
||||
|
||||
/// Creates a module showing if inside a guix-shell
|
||||
///
|
||||
/// The module will use the `$GUIX_ENVIRONMENT` environment variable to determine if it's
|
||||
/// inside a guix-shell and the name of it.
|
||||
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
let mut module = context.new_module("guix_shell");
|
||||
let config: GuixShellConfig = GuixShellConfig::try_load(module.config);
|
||||
|
||||
let is_guix_shell = context.get_env("GUIX_ENVIRONMENT").is_some();
|
||||
|
||||
if !is_guix_shell {
|
||||
return None;
|
||||
};
|
||||
|
||||
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
|
||||
formatter
|
||||
.map_meta(|variable, _| match variable {
|
||||
"symbol" => Some(config.symbol),
|
||||
_ => None,
|
||||
})
|
||||
.map_style(|variable| match variable {
|
||||
"style" => Some(Ok(config.style)),
|
||||
_ => None,
|
||||
})
|
||||
.parse(None, Some(context))
|
||||
});
|
||||
|
||||
module.set_segments(match parsed {
|
||||
Ok(segments) => segments,
|
||||
Err(error) => {
|
||||
log::warn!("Error in module `guix_shell`:\n{}", error);
|
||||
return None;
|
||||
}
|
||||
});
|
||||
|
||||
Some(module)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::test::ModuleRenderer;
|
||||
use nu_ansi_term::Color;
|
||||
|
||||
#[test]
|
||||
fn no_env_variables() {
|
||||
let actual = ModuleRenderer::new("guix_shell").collect();
|
||||
let expected = None;
|
||||
|
||||
assert_eq!(expected, actual);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn env_variables() {
|
||||
let actual = ModuleRenderer::new("guix_shell")
|
||||
.env(
|
||||
"GUIX_ENVIRONMENT",
|
||||
"/gnu/store/7vmfs4khf4fllsh83kqkxssbw3437qsh-profile",
|
||||
)
|
||||
.collect();
|
||||
let expected = Some(format!("via {} ", Color::Yellow.bold().paint("🐃 ")));
|
||||
|
||||
assert_eq!(expected, actual);
|
||||
}
|
||||
}
|
@ -30,6 +30,7 @@ mod git_metrics;
|
||||
mod git_state;
|
||||
mod git_status;
|
||||
mod golang;
|
||||
mod guix_shell;
|
||||
mod haskell;
|
||||
mod helm;
|
||||
mod hg_branch;
|
||||
@ -126,6 +127,7 @@ pub fn handle<'a>(module: &str, context: &'a Context) -> Option<Module<'a>> {
|
||||
"git_state" => git_state::module(context),
|
||||
"git_status" => git_status::module(context),
|
||||
"golang" => golang::module(context),
|
||||
"guix_shell" => guix_shell::module(context),
|
||||
"haskell" => haskell::module(context),
|
||||
"helm" => helm::module(context),
|
||||
"hg_branch" => hg_branch::module(context),
|
||||
@ -233,6 +235,7 @@ pub fn description(module: &str) -> &'static str {
|
||||
"git_state" => "The current git operation, and it's progress",
|
||||
"git_status" => "Symbol representing the state of the repo",
|
||||
"golang" => "The currently installed version of Golang",
|
||||
"guix_shell" => "The guix-shell environment",
|
||||
"haskell" => "The selected version of the Haskell toolchain",
|
||||
"helm" => "The currently installed version of Helm",
|
||||
"hg_branch" => "The active branch of the repo in your current directory",
|
||||
|
Loading…
Reference in New Issue
Block a user