From cdf0d12937adbe31ba0bb4f93258fdb6bf3dbd3a Mon Sep 17 00:00:00 2001 From: Verdayne Graham <9086968+verdayne@users.noreply.github.com> Date: Sat, 22 Oct 2022 12:17:33 +0000 Subject: [PATCH 1/7] refactor(nu): simplify getting term width (#4503) refactor(init,nu): simplify getting term width --- src/init/starship.nu | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/init/starship.nu b/src/init/starship.nu index b9fc7bea2..95a9b0b18 100644 --- a/src/init/starship.nu +++ b/src/init/starship.nu @@ -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)" } From 2db88b47b9f640e2e3187029d4ebeab2796e9537 Mon Sep 17 00:00:00 2001 From: Jan Klass Date: Sat, 22 Oct 2022 20:28:29 +0200 Subject: [PATCH 2/7] docs(config): Add missing default values (#4520) * docs(config): Add missing empty table default values as empty inline tables * docs(config): Add missing empty string default values in shell and vcsh --- docs/config/README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/config/README.md b/docs/config/README.md index e4094b613..0c2d863e5 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -337,8 +337,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 +1464,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. | @@ -2174,8 +2174,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 +3330,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 +3857,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. | From a40f4c9794188491e514b82510d850f4223357aa Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 23 Oct 2022 12:47:17 +0000 Subject: [PATCH 3/7] build(deps): update rust crate quick-xml to 0.26.0 --- Cargo.lock | 6 +++--- Cargo.toml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index db7d34f01..e100646a1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", ] @@ -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", diff --git a/Cargo.toml b/Cargo.toml index b9362ca3e..9003ec594 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" From 3d972d65c273de85862bb5ada654ff1b332a0458 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 24 Oct 2022 01:48:12 +0000 Subject: [PATCH 4/7] build(deps): update rust crate shadow-rs to 0.17.1 --- Cargo.lock | 4 ++-- Cargo.toml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e100646a1..a5c4bea47 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/Cargo.toml b/Cargo.toml index 9003ec594..321592a68 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 } @@ -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] From c3cd499a30ccefcc14eaa60156da7ef98ab6390c Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 24 Oct 2022 23:29:36 +0000 Subject: [PATCH 5/7] build(deps): update rust crate windows to 0.43.0 --- Cargo.lock | 6 +++--- Cargo.toml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a5c4bea47..fb1c66e3f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/Cargo.toml b/Cargo.toml index 321592a68..25616ba9f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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", From d4bcc519e61524e1fe30f82412a09af113d75287 Mon Sep 17 00:00:00 2001 From: Thierry Delafontaine Date: Tue, 25 Oct 2022 07:44:04 +0200 Subject: [PATCH 6/7] feat(guix_shell): Initial implementation (#4397) * feat(guix_shell): Initial implementation (#3999) * fix(guix_shell): Change guix nerd font icon to water buffalo emoji * fix(guix_shell): Added guix_shell entries in preset files * fix(guix_shell): Moved guix_shell config docs in to the correct place (alphabetically) --- .github/config-schema.json | 35 ++++++++++ .../presets/toml/bracketed-segments.toml | 3 + .../presets/toml/nerd-font-symbols.toml | 3 + .../presets/toml/plain-text-symbols.toml | 3 + docs/config/README.md | 34 +++++++++ src/configs/guix_shell.rs | 26 +++++++ src/configs/mod.rs | 3 + src/configs/starship_root.rs | 1 + src/module.rs | 1 + src/modules/guix_shell.rs | 69 +++++++++++++++++++ src/modules/mod.rs | 3 + 11 files changed, 181 insertions(+) create mode 100644 src/configs/guix_shell.rs create mode 100644 src/modules/guix_shell.rs diff --git a/.github/config-schema.json b/.github/config-schema.json index 0e062b41a..5a0c78381 100644 --- a/.github/config-schema.json +++ b/.github/config-schema.json @@ -620,6 +620,19 @@ } ] }, + "guix_shell": { + "default": { + "disabled": false, + "format": "via [$symbol]($style) ", + "style": "yellow bold", + "symbol": "🐃 " + }, + "allOf": [ + { + "$ref": "#/definitions/GuixShellConfig" + } + ] + }, "haskell": { "default": { "detect_extensions": [ @@ -3091,6 +3104,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": { diff --git a/docs/.vuepress/public/presets/toml/bracketed-segments.toml b/docs/.vuepress/public/presets/toml/bracketed-segments.toml index b8138d79c..cdd48cf94 100644 --- a/docs/.vuepress/public/presets/toml/bracketed-segments.toml +++ b/docs/.vuepress/public/presets/toml/bracketed-segments.toml @@ -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)\]' diff --git a/docs/.vuepress/public/presets/toml/nerd-font-symbols.toml b/docs/.vuepress/public/presets/toml/nerd-font-symbols.toml index 7d8adfb56..f8f2700b3 100644 --- a/docs/.vuepress/public/presets/toml/nerd-font-symbols.toml +++ b/docs/.vuepress/public/presets/toml/nerd-font-symbols.toml @@ -31,6 +31,9 @@ symbol = " " [golang] symbol = " " +[guix_shell] +symbol = " " + [haskell] symbol = " " diff --git a/docs/.vuepress/public/presets/toml/plain-text-symbols.toml b/docs/.vuepress/public/presets/toml/plain-text-symbols.toml index 5360d7936..bc555349b 100644 --- a/docs/.vuepress/public/presets/toml/plain-text-symbols.toml +++ b/docs/.vuepress/public/presets/toml/plain-text-symbols.toml @@ -64,6 +64,9 @@ symbol = "git " [golang] symbol = "go " +[guix_shell] +symbol = "guix " + [hg_branch] symbol = "hg " diff --git a/docs/config/README.md b/docs/config/README.md index 0c2d863e5..b1adce8e5 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -250,6 +250,7 @@ $elixir\ $elm\ $erlang\ $golang\ +$guix_shell\ $haskell\ $helm\ $java\ @@ -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. diff --git a/src/configs/guix_shell.rs b/src/configs/guix_shell.rs new file mode 100644 index 000000000..8bedc706f --- /dev/null +++ b/src/configs/guix_shell.rs @@ -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, + } + } +} diff --git a/src/configs/mod.rs b/src/configs/mod.rs index 582d56c56..035b09e0a 100644 --- a/src/configs/mod.rs +++ b/src/configs/mod.rs @@ -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>, diff --git a/src/configs/starship_root.rs b/src/configs/starship_root.rs index 11f6627a5..48116eb28 100644 --- a/src/configs/starship_root.rs +++ b/src/configs/starship_root.rs @@ -86,6 +86,7 @@ pub const PROMPT_ORDER: &[&str] = &[ "zig", // ↑ Toolchain version modules ↑ "buf", + "guix_shell", "nix_shell", "conda", "meson", diff --git a/src/module.rs b/src/module.rs index 31881ee7d..871c2f9d8 100644 --- a/src/module.rs +++ b/src/module.rs @@ -41,6 +41,7 @@ pub const ALL_MODULES: &[&str] = &[ "git_state", "git_status", "golang", + "guix_shell", "haskell", "helm", "hg_branch", diff --git a/src/modules/guix_shell.rs b/src/modules/guix_shell.rs new file mode 100644 index 000000000..6ee0a7b5e --- /dev/null +++ b/src/modules/guix_shell.rs @@ -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> { + 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); + } +} diff --git a/src/modules/mod.rs b/src/modules/mod.rs index 62de0ec6c..06a4fe04f 100644 --- a/src/modules/mod.rs +++ b/src/modules/mod.rs @@ -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> { "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", From 888afbed35cc0fcf3054797aba650296ff6a75c2 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 25 Oct 2022 06:23:23 +0000 Subject: [PATCH 7/7] build(deps): update dependency taplo-cli to 0.7.2 --- .github/workflows/format-workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/format-workflow.yml b/.github/workflows/format-workflow.yml index 8d9b7b3c3..ffde218d2 100644 --- a/.github/workflows/format-workflow.yml +++ b/.github/workflows/format-workflow.yml @@ -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