From b816a0bf70274b4e1017afbfd24ff579c39b44ba Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Sat, 22 Jan 2022 19:46:56 +0100 Subject: [PATCH] feat: templates for all segments --- docs/docs/config-segment.md | 2 + .../{config-decorations.md => config-text.md} | 24 +- docs/docs/config-title.md | 15 +- docs/docs/config-transient.mdx | 4 +- docs/docs/segment-angular.md | 9 +- docs/docs/segment-aws.md | 7 +- docs/docs/segment-az.md | 10 +- docs/docs/segment-azfunc.md | 11 +- docs/docs/segment-battery.md | 7 +- docs/docs/segment-brewfather.md | 21 +- docs/docs/segment-command.md | 5 + docs/docs/segment-crystal.md | 9 +- docs/docs/segment-dart.md | 9 +- docs/docs/segment-dotnet.md | 9 +- docs/docs/segment-executiontime.md | 4 +- docs/docs/segment-exit.md | 4 +- docs/docs/segment-git.mdx | 10 +- docs/docs/segment-golang.md | 8 +- docs/docs/segment-ipify.md | 7 +- docs/docs/segment-java.md | 8 +- docs/docs/segment-julia.md | 9 +- docs/docs/segment-kubectl.md | 7 +- docs/docs/segment-nbgv.mdx | 10 +- docs/docs/segment-nightscout.md | 11 +- docs/docs/segment-node.md | 7 +- docs/docs/segment-os.md | 6 +- docs/docs/segment-owm.md | 7 +- docs/docs/segment-path.md | 7 +- docs/docs/segment-php.md | 9 +- docs/docs/segment-plastic.md | 12 +- docs/docs/segment-posh-git.mdx | 5 + docs/docs/segment-python.md | 9 +- docs/docs/segment-root.md | 6 +- docs/docs/segment-ruby.md | 9 +- docs/docs/segment-rust.md | 9 +- docs/docs/segment-session.md | 10 +- docs/docs/segment-shell.md | 6 + docs/docs/segment-spotify.md | 21 +- docs/docs/segment-strava.mdx | 7 +- docs/docs/{sysinfo.md => segment-sysinfo.md} | 9 +- docs/docs/segment-terraform.md | 7 +- docs/docs/segment-text.md | 10 +- docs/docs/segment-time.md | 13 +- docs/docs/segment-wakatime.md | 7 +- docs/docs/segment-wifi.md | 10 +- docs/docs/segment-winreg.md | 9 +- docs/docs/segment-ytm.md | 15 +- docs/sidebars.js | 2 +- src/environment.go | 1 + src/segment_angular.go | 6 +- src/segment_az_functions.go | 6 +- src/segment_command.go | 29 +- src/segment_command_test.go | 81 +++--- src/segment_crystal.go | 6 +- src/segment_dart.go | 6 +- src/segment_deprecated.go | 31 +- src/segment_deprecated_test.go | 35 ++- src/segment_dotnet.go | 27 +- src/segment_executiontime.go | 12 +- src/segment_exit.go | 24 +- src/segment_exit_test.go | 3 +- src/segment_git.go | 54 ++-- src/segment_git_test.go | 30 +- src/segment_golang.go | 6 +- src/segment_java.go | 6 +- src/segment_julia.go | 6 +- src/segment_language.go | 51 ++-- src/segment_os.go | 66 ++--- src/segment_os_test.go | 13 +- src/segment_owm.go | 24 +- src/segment_path.go | 10 +- src/segment_path_test.go | 2 + src/segment_php.go | 16 +- src/segment_plastic.go | 26 +- src/segment_plastic_test.go | 8 +- src/segment_posh_git.go | 23 +- src/segment_posh_git_test.go | 4 +- src/segment_root.go | 17 +- src/segment_ruby.go | 14 +- src/segment_rust.go | 6 +- src/segment_session.go | 24 +- src/segment_session_test.go | 83 +++--- src/segment_shell.go | 28 +- src/segment_shell_test.go | 4 + src/segment_spotify.go | 59 ++-- src/segment_spotify_darwin.go | 9 +- src/segment_spotify_darwin_test.go | 1 + src/segment_spotify_test.go | 39 +-- src/segment_spotify_windows.go | 9 +- src/segment_spotify_windows_test.go | 1 + src/segment_spotify_wsl.go | 7 +- src/segment_spotify_wsl_test.go | 1 + src/segment_text.go | 23 +- src/segment_time.go | 26 +- src/segment_ytm.go | 51 ++-- src/segment_ytm_test.go | 51 +--- src/template.go | 3 +- src/test/jandedobbeleer-palette.omp.json | 12 +- src/test/jandedobbeleer.omp.json | 12 +- themes/amro.omp.json | 2 +- themes/atomic.omp.json | 2 +- themes/atomicBit.omp.json | 2 +- themes/blue-owl.omp.json | 2 +- themes/bubbles.omp.json | 12 +- themes/bubblesline.omp.json | 12 +- themes/clean-detailed.omp.json | 4 +- themes/grandpa-style.omp.json | 2 +- themes/hotstick.minimal.omp.json | 2 +- themes/hunk.omp.json | 4 +- themes/iterm2.omp.json | 2 +- themes/jandedobbeleer.omp.json | 12 +- themes/jblab_2021.omp.json | 3 +- themes/jonnychipz.omp.json | 7 +- themes/mojada.omp.json | 2 +- themes/negligible.omp.json | 2 +- themes/night-owl.omp.json | 2 +- themes/patriksvensson.omp.json | 2 +- themes/pixelrobots.omp.json | 7 +- themes/powerlevel10k_modern.omp.json | 2 +- themes/powerlevel10k_rainbow.omp.json | 12 +- themes/rudolfs-dark.omp.json | 3 +- themes/rudolfs-light.omp.json | 3 +- themes/schema.json | 117 +------- themes/slim.omp.json | 7 +- themes/slimfat.omp.json | 7 +- themes/smoothie.omp.json | 2 +- themes/sonicboom_dark.omp.json | 270 +++++++++--------- themes/sonicboom_light.omp.json | 270 +++++++++--------- themes/star.omp.json | 4 +- themes/stelbent.minimal.omp.json | 2 +- themes/thecyberden.omp.json | 2 +- themes/unicorn.omp.json | 2 +- themes/wopian.omp.json | 9 +- themes/xtoys.omp.json | 2 +- themes/ys.omp.json | 4 +- 135 files changed, 1109 insertions(+), 1216 deletions(-) rename docs/docs/{config-decorations.md => config-text.md} (55%) rename docs/docs/{sysinfo.md => segment-sysinfo.md} (84%) diff --git a/docs/docs/config-segment.md b/docs/docs/config-segment.md index 08a66e44..af709a2b 100644 --- a/docs/docs/config-segment.md +++ b/docs/docs/config-segment.md @@ -146,6 +146,7 @@ You can use these on any segment, the engine is responsible for adding them corr - postfix: `string` - include_folders: `[]string` - exclude_folders: `[]string` +- template: `string` - A go text/template [template][templates] to render the text #### Prefix @@ -217,3 +218,4 @@ This means that for user Bill, who has a user account `Bill` on Windows and `bil [fg-templ]: /docs/config-overview#foreground-templates [regex]: https://www.regular-expressions.info/tutorial.html [aws]: /docs/aws +[templates]: /docs/config-text#templates diff --git a/docs/docs/config-decorations.md b/docs/docs/config-text.md similarity index 55% rename from docs/docs/config-decorations.md rename to docs/docs/config-text.md index 104b49ef..d260ae2a 100644 --- a/docs/docs/config-decorations.md +++ b/docs/docs/config-text.md @@ -1,10 +1,24 @@ --- -id: config-text-style -title: Text style -sidebar_label: Text style +id: config-text +title: Text +sidebar_label: Text --- -## Text decorations +## Templates + +Every segment has a `template` property to tweak the text that is displayed. +Under the hood, this uses go's [text/template][go-text-template] feature extended with [sprig][sprig] and +offers a few standard properties to work with. + +- `.Root`: `boolean` - is the current user root/admin or not +- `.PWD`: `string` - the current working directory +- `.Folder`: `string` - the current working folder +- `.Shell`: `string` - the current shell name +- `.UserName`: `string` - the current user name +- `.HostName`: `string` - the host name +- `.Env.VarName`: `string` - Any environment variable where `VarName` is the environment variable name + +## Text decoration You can make use of the following syntax to decorate text: @@ -38,3 +52,5 @@ When using in a template, the syntax is like markdown: [terminal-list-hyperlinks]: https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda [path-segment]: /docs/path [git-segment]: /docs/git +[go-text-template]: https://golang.org/pkg/text/template/ +[sprig]: https://masterminds.github.io/sprig/ diff --git a/docs/docs/config-title.md b/docs/docs/config-title.md index cecc67ba..1eb8321a 100644 --- a/docs/docs/config-title.md +++ b/docs/docs/config-title.md @@ -30,22 +30,12 @@ To manipulate the console title, you can make use of the following properties: You can create a more custom console title with the use of `"console_title_style" = "template"`. When this is set, a `console_title_template` is also expected, otherwise, the title will remain empty. -Under the hood, this uses go's [text/template][go-text-template] feature extended with [sprig][sprig] and -offers a few standard properties to work with. - -- `.Root`: `boolean` - is the current user root/admin or not -- `.PWD`: `string` - the current working directory -- `.Folder`: `string` - the current working folder -- `.Shell`: `string` - the current shell name -- `.UserName`: `string` - the current user name -- `.HostName`: `string` - the host name -- `.Env.VarName`: `string` - Any environment variable where `VarName` is the environment variable name - -A `boolean` can be used for conditional display purposes, a `string` can be displayed. The following examples illustrate possible contents for `console_title_template`, provided the current working directory is `/usr/home/omp` and the shell is `zsh`. +To learn more about templates and their possibilities, have a look at the [template][templates] section. + ```json { "console_title_template": "{{.Folder}}{{if .Root}} :: root{{end}} :: {{.Shell}}", @@ -61,3 +51,4 @@ the current working directory is `/usr/home/omp` and the shell is `zsh`. [go-text-template]: https://golang.org/pkg/text/template/ [sprig]: https://masterminds.github.io/sprig/ +[templates]: /docs/config-text#templates diff --git a/docs/docs/config-transient.mdx b/docs/docs/config-transient.mdx index e44b7373..92904c86 100644 --- a/docs/docs/config-transient.mdx +++ b/docs/docs/config-transient.mdx @@ -49,10 +49,10 @@ The configuration has the following properties: - template: `string` - A go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the properties below - defaults to `{{ .Shell }}> ` -## Template Properties +## [Template][templates] Properties - `.Root`: `boolean` - is the current user root/admin or not -- `.Path`: `string` - the current working directory +- `.PWD`: `string` - the current working directory - `.Folder`: `string` - the current working folder - `.Shell`: `string` - the current shell name - `.UserName`: `string` - the current user name diff --git a/docs/docs/segment-angular.md b/docs/docs/segment-angular.md index 352d9580..4a12cb28 100644 --- a/docs/docs/segment-angular.md +++ b/docs/docs/segment-angular.md @@ -25,14 +25,12 @@ Display the currently active Angular CLI version. ## Properties -- display_version: `boolean` - display the active version or not; useful if all you need is an icon indicating `ng` +- fetch_version: `boolean` - fetch the active version or not; useful if all you need is an icon indicating `ng` - display_mode: `string` - determines when the segment is displayed - `always`: the segment is always displayed - `files`: the segment is only displayed when `angular.json` file is present (default) -- template: `string` - A go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the -properties below. Defaults to `{{ .Full }}` -## Template Properties +## [Template][templates] Properties - `.Full`: `string` - the full version - `.Major`: `string` - major number @@ -42,5 +40,4 @@ properties below. Defaults to `{{ .Full }}` - `.BuildMetadata`: `string` - build metadata - `.Error`: `string` - when fetching the version string errors -[go-text-template]: https://golang.org/pkg/text/template/ -[sprig]: https://masterminds.github.io/sprig/ +[templates]: /docs/config-text#templates diff --git a/docs/docs/segment-aws.md b/docs/docs/segment-aws.md index f1d5e71d..55992b3a 100644 --- a/docs/docs/segment-aws.md +++ b/docs/docs/segment-aws.md @@ -26,15 +26,12 @@ Display the currently active AWS profile and region. ## Properties -- template: `string` - A go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the -properties below - defaults to `{{.Context}}{{if .Namespace}} :: {{.Namespace}}{{end}}` - display_default: `boolean` - display the segment or not when the user profile matches `default` - defaults to `true` -## Template Properties +## [Template][templates] Properties - `.Profile`: `string` - the currently active profile - `.Region`: `string` - the currently active region -[go-text-template]: https://golang.org/pkg/text/template/ -[sprig]: https://masterminds.github.io/sprig/ +[templates]: /docs/config-text#templates diff --git a/docs/docs/segment-az.md b/docs/docs/segment-az.md index 43d820bc..f8d73f02 100644 --- a/docs/docs/segment-az.md +++ b/docs/docs/segment-az.md @@ -24,12 +24,7 @@ Display the currently active Azure subscription information. } ``` -## Properties - -- template: `string` - A go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the -properties below - defaults to `{{.Name}}` - -## Template Properties +## [Template][templates] Properties - `.EnvironmentName`: `string` - the account environment name - `.HomeTenantID`: `string` - the home tenant id @@ -41,5 +36,4 @@ properties below - defaults to `{{.Name}}` - `.UserName`: `string` - the user name - `.Origin`: `string` - where we received the information from, can be `CLI` or `PWSH` -[go-text-template]: https://golang.org/pkg/text/template/ -[sprig]: https://masterminds.github.io/sprig/ +[templates]: /docs/config-text#templates diff --git a/docs/docs/segment-azfunc.md b/docs/docs/segment-azfunc.md index 2abc25c8..3db64957 100644 --- a/docs/docs/segment-azfunc.md +++ b/docs/docs/segment-azfunc.md @@ -19,7 +19,7 @@ Display the currently active Azure functions CLI version. "background": "#FEAC19", "properties": { "prefix": " \uf0e7 ", - "display_version": true, + "fetch_version": true, "display_mode": "files" } } @@ -27,16 +27,14 @@ Display the currently active Azure functions CLI version. ## Properties -- display_version: `boolean` - display the Azure functions CLI version - defaults to `true` +- fetch_version: `boolean` - fetch the Azure functions CLI version - defaults to `true` - display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true` - missing_command_text: `string` - text to display when the command is missing - defaults to empty - display_mode: `string` - determines when the segment is displayed - `always`: the segment is always displayed - `files`: the segment is only displayed when a `host.json` or `local.settings.json` files is present (default) -- template: `string` - A go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the -properties below. Defaults to `{{ .Full }}` -## Template Properties +## [Template][templates] Properties - `.Full`: `string` - the full version - `.Major`: `string` - major number @@ -46,5 +44,4 @@ properties below. Defaults to `{{ .Full }}` - `.BuildMetadata`: `string` - build metadata - `.Error`: `string` - when fetching the version string errors -[go-text-template]: https://golang.org/pkg/text/template/ -[sprig]: https://masterminds.github.io/sprig/ +[templates]: /docs/config-text#templates diff --git a/docs/docs/segment-battery.md b/docs/docs/segment-battery.md index 72380ed7..75f89743 100644 --- a/docs/docs/segment-battery.md +++ b/docs/docs/segment-battery.md @@ -34,14 +34,12 @@ Battery displays the remaining power percentage for your battery. ## Properties -- template: `string` - A go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the -properties below - defaults to `{{.Icon}}{{ if not .Error }}{{.Percentage}}{{ end }}{{.Error}}` - display_error: `boolean` - show the error context when failing to retrieve the battery information - defaults to `false` - charging_icon: `string` - icon to display on the left when charging - defaults to empty - discharging_icon: `string` - icon to display on the left when discharging - defaults to empty - charged_icon: `string` - icon to display on the left when fully charged - defaults to empty -## Template Properties +## [Template][templates] Properties - `.State`: `struct` - the battery state, has a `.String` function - `.Current`: `float64` - Current (momentary) charge rate (in mW). @@ -60,5 +58,4 @@ the same value as `Voltage`, for convenience [colors]: /docs/config-colors [battery]: https://github.com/distatus/battery/blob/master/battery.go#L78 -[go-text-template]: https://golang.org/pkg/text/template/ -[sprig]: https://masterminds.github.io/sprig/ +[templates]: /docs/config-text#templates diff --git a/docs/docs/segment-brewfather.md b/docs/docs/segment-brewfather.md index 8969e666..f71cd7e1 100644 --- a/docs/docs/segment-brewfather.md +++ b/docs/docs/segment-brewfather.md @@ -7,10 +7,10 @@ sidebar_label: Brewfather ## What Calling all brewers! Keep up-to-date with the status of your [Brewfather][brewfather] batch directly in your - commandline prompt using the brewfather segment! +commandline prompt using the brewfather segment! - You will need your User ID and API Key as generated in - Brewfather's Settings screen, enabled with **batches.read** and **recipes.read** scopes. +You will need your User ID and API Key as generated in +Brewfather's Settings screen, enabled with **batches.read** and **recipes.read** scopes. ## Sample Configuration @@ -46,8 +46,6 @@ NOTE: Temperature units are in degrees C and specific gravity is expressed as `X - batch_id: `string` - Get this by navigating to the desired batch on the brewfather website, the batch id is at the end of the URL in the address bar. - http_timeout: `int` in milliseconds - How long to wait for the Brewfather service to answer the request. Default 2 seconds. -- template: `string` - a go [text/template][go-text-template] template extended -with [sprig][sprig] utilizing the properties below. - cache_timeout: `int` in minutes - How long to wait before updating the data from Brewfather. Default is 5 minutes. - day_icon: `string` - icon or letter to use to indicate days. Default is "d". @@ -56,7 +54,7 @@ You can override the icons for temperature trend as used by template property `. - doubleup_icon - for increases of more than 4°C, default is ↑↑ - singleup_icon - increase 2-4°C, default is ↑ - fortyfiveup_icon - increase 0.5-2°C, default is ↗ -- flat_icon -change less than 0.5°C, default is → +- flat_icon - change less than 0.5°C, default is → - fortyfivedown_icon - decrease 0.5-2°C, default is ↘ - singledown_icon - decrease 2-4°C, default is ↓ - doubledown_icon - decrease more than 4°C, default is ↓↓ @@ -70,7 +68,7 @@ You can override the default icons for batch status as used by template property - completed_status_icon - archived_status_icon -## Template Properties +## [Template][templates] Properties Commonly used fields @@ -85,7 +83,7 @@ Commonly used fields - .BatchNumer `int` - The number of this batch - .MeasuredAbv: `float` - The ABV for the batch - either estimated from recipe or calculated from entered OG and FG values - .ReadingAge `int` - age in hours of most recent reading or -1 if there are no readings available - + .Reading contains the most recent data from devices or manual entry as visible on the Brewfather's batch Readings graph. If there are no readings available, .Reading will be null. @@ -95,7 +93,7 @@ If there are no readings available, .Reading will be null. - .Reading.Comment `string` - comment attached to this reading - .Reading.DeviceType `string` - source of the reading, e.g. "Tilt" - .Reading.DeviceID `string` - id of the device, e.g. "PINK" - + Additional template properties - .MeasuredOg: `float` - The OG for the batch as manually entered into Brewfather @@ -147,7 +145,7 @@ The following conversion functions are available to the template to convert to o - SGToBrix - input `float` SG in x.xxx decimal; output `float` Brix (2 decimal places) - SGToPlato - input `float` SG in x.xxx decimal; output `float` Plato (2 decimal places) - + *(These use the polynomial conversions from [Wikipedia][wikipedia_gravity_page])* #### Example @@ -166,7 +164,6 @@ To display gravity as SG in XXXX format (e.g. "1020" instead of "1.020"), use th } ```` -[go-text-template]: https://golang.org/pkg/text/template/ -[sprig]: https://masterminds.github.io/sprig/ +[templates]: /docs/config-text#templates [brewfather]: http://brewfather.app [wikipedia_gravity_page]:https://en.wikipedia.org/wiki/Brix#Specific_gravity_2 diff --git a/docs/docs/segment-command.md b/docs/docs/segment-command.md index 9689f16d..41e66ac8 100644 --- a/docs/docs/segment-command.md +++ b/docs/docs/segment-command.md @@ -45,4 +45,9 @@ error). The `&&` functionality will join the output of the commands when success - shell: `string` - the shell in which to run the command in. Uses `shell -c command` under the hood. - command: `string` - the command(s) to run +## [Template][templates] Properties + +- `.Output`: `string` - the output of the command. + [env]: /docs/environment +[templates]: /docs/config-text#templates diff --git a/docs/docs/segment-crystal.md b/docs/docs/segment-crystal.md index e21733cc..54efb5e0 100644 --- a/docs/docs/segment-crystal.md +++ b/docs/docs/segment-crystal.md @@ -26,16 +26,14 @@ Display the currently active crystal version. ## Properties - home_enabled: `boolean` - display the segment in the HOME folder or not - defaults to `false` -- display_version: `boolean` - display the julia version - defaults to `true` +- fetch_version: `boolean` - fetch the julia version - defaults to `true` - display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true` - missing_command_text: `string` - text to display when the command is missing - defaults to empty - display_mode: `string` - determines when the segment is displayed - `always`: the segment is always displayed - `files`: the segment is only displayed when `*.cr` or `shard.yml` files are present (default) -- template: `string` - A go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the - properties below. Defaults to `{{ .Full }}` -## Template Properties +## [Template][templates] Properties - `.Full`: `string` - the full version - `.Major`: `string` - major number @@ -45,5 +43,4 @@ Display the currently active crystal version. - `.BuildMetadata`: `string` - build metadata - `.Error`: `string` - when fetching the version string errors -[go-text-template]: https://golang.org/pkg/text/template/ -[sprig]: https://masterminds.github.io/sprig/ +[templates]: /docs/config-text#templates diff --git a/docs/docs/segment-dart.md b/docs/docs/segment-dart.md index 631f029a..4ef1acb1 100644 --- a/docs/docs/segment-dart.md +++ b/docs/docs/segment-dart.md @@ -26,17 +26,15 @@ Display the currently active dart version. ## Properties - home_enabled: `boolean` - display the segment in the HOME folder or not - defaults to `false` -- display_version: `boolean` - display the dart version - defaults to `true` +- fetch_version: `boolean` - fetch the dart version - defaults to `true` - display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true` - missing_command_text: `string` - text to display when the command is missing - defaults to empty - display_mode: `string` - determines when the segment is displayed - `always`: the segment is always displayed - `files`: the segment is only displayed when `*.dart`, `pubspec.yaml`, `pubspec.yml`, `pubspec.lock` files or the `.dart_tool` folder are present (default) -- template: `string` - A go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the -properties below. Defaults to `{{ .Full }}` -## Template Properties +## [Template][templates] Properties - `.Full`: `string` - the full version - `.Major`: `string` - major number @@ -46,5 +44,4 @@ properties below. Defaults to `{{ .Full }}` - `.BuildMetadata`: `string` - build metadata - `.Error`: `string` - when fetching the version string errors -[go-text-template]: https://golang.org/pkg/text/template/ -[sprig]: https://masterminds.github.io/sprig/ +[templates]: /docs/config-text#templates diff --git a/docs/docs/segment-dotnet.md b/docs/docs/segment-dotnet.md index f46cb7c6..7ddfa3d1 100644 --- a/docs/docs/segment-dotnet.md +++ b/docs/docs/segment-dotnet.md @@ -26,7 +26,7 @@ Display the currently active .NET SDK version. ## Properties - home_enabled: `boolean` - display the segment in the HOME folder or not - defaults to `false` -- display_version: `boolean` - display the active version or not; useful if all you need is an icon indicating `dotnet` +- fetch_version: `boolean` - fetch the active version or not; useful if all you need is an icon indicating `dotnet` is present - defaults to `true` - display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true` - missing_command_text: `string` - text to display when the command is missing - defaults to empty @@ -36,12 +36,10 @@ Display the currently active .NET SDK version. or `*.fsproj` files are present (default) - unsupported_version_icon: `string` - text/icon that is displayed when the active .NET SDK version (e.g., one specified by `global.json`) is not installed/supported - defaults to `\uf071` (X in a rectangle box) -- template: `string` - A go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the -properties below. Defaults to `{{ .Full }}` - version_url_template: `string` - A go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the properties below. Defaults does nothing(backward compatibility). -## Template Properties +## [Template][templates] Properties - `.Full`: `string` - the full version - `.Major`: `string` - major number @@ -51,5 +49,4 @@ with [sprig][sprig] utilizing the properties below. Defaults does nothing(backwa - `.BuildMetadata`: `string` - build metadata - `.Error`: `string` - when fetching the version string errors -[go-text-template]: https://golang.org/pkg/text/template/ -[sprig]: https://masterminds.github.io/sprig/ +[templates]: /docs/config-text#templates diff --git a/docs/docs/segment-executiontime.md b/docs/docs/segment-executiontime.md index e6d30e19..0996c286 100644 --- a/docs/docs/segment-executiontime.md +++ b/docs/docs/segment-executiontime.md @@ -49,7 +49,9 @@ Style specifies the format in which the time will be displayed. The table below | amarillo | `0.001s` | `2.1s` | `182.1s` | `14,582.1s` | | round | `1ms` | `2s` | `3m 2s` | `4h 3m` | -## Template Properties +## [Template][templates] Properties - `.Ms`: `number` - the execution time in milliseconds - `.FormattedMs`: `string` - the formatted value based on the `style` above. + +[templates]: /docs/config-text#templates diff --git a/docs/docs/segment-exit.md b/docs/docs/segment-exit.md index 6ed4cc21..a80f3ad1 100644 --- a/docs/docs/segment-exit.md +++ b/docs/docs/segment-exit.md @@ -35,7 +35,9 @@ Displays the last exit code or that the last command failed based on the configu [colors]: /docs/config-colors -## Template Properties +## [Template][templates] Properties - `.Code`: `number` - the last known exit code - `.Text`: `string` - the textual meaning linked to exit code (if applicable, otherwise identical to `.Code`) + +[templates]: /docs/config-text#templates diff --git a/docs/docs/segment-git.mdx b/docs/docs/segment-git.mdx index a42f926b..f848abf2 100644 --- a/docs/docs/segment-git.mdx +++ b/docs/docs/segment-git.mdx @@ -53,9 +53,6 @@ An alternative is to use the [Posh-Git segment][poshgit] ## Properties -- template: `string` - A go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the -properties below - defaults to empty. - ### Fetching information As doing multiple git calls can slow down the prompt experience, we do not fetch information by default. @@ -96,7 +93,7 @@ You can set the following properties to `true` to enable fetching additional inf - azure_devops_icon: `string` - icon/text to display when the upstream is Azure DevOps - defaults to `\uFD03 ` - git_icon: `string` - icon/text to display when the upstream is not known/mapped - defaults to `\uE5FB ` -## Template Properties +## [Template][templates] Properties - `.Working`: `GitStatus` - changes in the working tree (see below) - `.Staging`: `GitStatus` - staged changes in the work tree (see below) @@ -121,6 +118,5 @@ You can set the following properties to `true` to enable fetching additional inf - `.String`: `string` - a string representation of the changes above [poshgit]: /docs/poshgit -[go-text-template]: https://golang.org/pkg/text/template/ -[sprig]: https://masterminds.github.io/sprig/ -[hyperlinks]: /docs/config-text-style#hyperlinks +[templates]: /docs/config-text#templates +[hyperlinks]: /docs/config-text#hyperlinks diff --git a/docs/docs/segment-golang.md b/docs/docs/segment-golang.md index d32155b0..2dfb348d 100644 --- a/docs/docs/segment-golang.md +++ b/docs/docs/segment-golang.md @@ -26,17 +26,15 @@ Display the currently active golang version. ## Properties - home_enabled: `boolean` - display the segment in the HOME folder or not - defaults to `false` -- display_version: `boolean` - display the golang version - defaults to `true` +- fetch_version: `boolean` - display the golang version - defaults to `true` - display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true` - missing_command_text: `string` - text to display when the command is missing - defaults to empty - display_mode: `string` - determines when the segment is displayed - `always`: the segment is always displayed - `files`: the segment is only displayed when `*.go` or `go.mod` files are present (default) -- template: `string` - A go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the -properties below. Defaults to `{{ .Full }}` - parse_mod_file: `boolean`: parse the go.mod file instead of calling `go version` -## Template Properties +## [Template][templates] Properties - `.Full`: `string` - the full version - `.Major`: `string` - major number @@ -45,3 +43,5 @@ properties below. Defaults to `{{ .Full }}` - `.Prerelease`: `string` - prerelease info text - `.BuildMetadata`: `string` - build metadata - `.Error`: `string` - when fetching the version string errors + +[templates]: /docs/config-text#templates diff --git a/docs/docs/segment-ipify.md b/docs/docs/segment-ipify.md index 78f6999c..194d0cc2 100644 --- a/docs/docs/segment-ipify.md +++ b/docs/docs/segment-ipify.md @@ -33,13 +33,10 @@ sidebar_label: Ipify defaults to 20ms - cache_timeout: `int` in minutes - How long do you want your IP address cached? - defaults to 10 min -- template: `string` - a go [text/template][go-text-template] template extended - with [sprig][sprig] utilizing the properties below. - defaults to `{{ .IP }}` -## Template Properties +## [Template][templates] Properties - .IP: `string` - Your external IP address -[go-text-template]: https://golang.org/pkg/text/template/ -[sprig]: https://masterminds.github.io/sprig/ +[templates]: /docs/config-text#templates [ipify]: https://www.ipify.org/ diff --git a/docs/docs/segment-java.md b/docs/docs/segment-java.md index cb358d83..793fc037 100644 --- a/docs/docs/segment-java.md +++ b/docs/docs/segment-java.md @@ -26,7 +26,7 @@ Display the currently active java version. ## Properties - home_enabled: `boolean` - display the segment in the HOME folder or not - defaults to `false` -- display_version: `boolean` - display the java version - defaults to `true` +- fetch_version: `boolean` - display the java version - defaults to `true` - display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true` - missing_command_text: `string` - text to display when the java command is missing - defaults to empty - display_mode: `string` - determines when the segment is displayed @@ -45,10 +45,8 @@ Display the currently active java version. - `*.jar` - `*.clj` - `*.cljc` -- template: `string` - A go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the -properties below. Defaults to `{{ .Full }}` -## Template Properties +## [Template][templates] Properties - `.Full`: `string` - the full version - `.Major`: `string` - major number @@ -57,3 +55,5 @@ properties below. Defaults to `{{ .Full }}` - `.Prerelease`: `string` - prerelease info text - `.BuildMetadata`: `string` - build metadata - `.Error`: `string` - when fetching the version string errors + +[templates]: /docs/config-text#templates diff --git a/docs/docs/segment-julia.md b/docs/docs/segment-julia.md index 74d705ac..4ffaff3e 100644 --- a/docs/docs/segment-julia.md +++ b/docs/docs/segment-julia.md @@ -26,16 +26,14 @@ Display the currently active julia version. ## Properties - home_enabled: `boolean` - display the segment in the HOME folder or not - defaults to `false` -- display_version: `boolean` - display the julia version - defaults to `true` +- fetch_version: `boolean` - display the julia version - defaults to `true` - display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true` - missing_command_text: `string` - text to display when the command is missing - defaults to empty - display_mode: `string` - determines when the segment is displayed - `always`: the segment is always displayed - `files`: the segment is only displayed when `*.jl` files are present (default) -- template: `string` - A go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the -properties below. Defaults to `{{ .Full }}` -## Template Properties +## [Template][templates] Properties - `.Full`: `string` - the full version - `.Major`: `string` - major number @@ -45,5 +43,4 @@ properties below. Defaults to `{{ .Full }}` - `.BuildMetadata`: `string` - build metadata - `.Error`: `string` - when fetching the version string errors -[go-text-template]: https://golang.org/pkg/text/template/ -[sprig]: https://masterminds.github.io/sprig/ +[templates]: /docs/config-text#templates diff --git a/docs/docs/segment-kubectl.md b/docs/docs/segment-kubectl.md index 749d478f..870705c8 100644 --- a/docs/docs/segment-kubectl.md +++ b/docs/docs/segment-kubectl.md @@ -26,13 +26,11 @@ Display the currently active Kubernetes context name and namespace name. ## Properties -- template: `string` - A go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the -properties below - defaults to `{{.Context}}{{if .Namespace}} :: {{.Namespace}}{{end}}` - display_error: `boolean` - show the error context when failing to retrieve the kubectl information - defaults to `false` - parse_kubeconfig: `boolean` - parse kubeconfig files instead of calling out to kubectl to improve performance - defaults to `false` -## Template Properties +## [Template][templates] Properties - `.Context`: `string` - the current kubectl context - `.Namespace`: `string` - the current kubectl context namespace @@ -46,5 +44,4 @@ It is common for the Kubernetes "default" namespace to be used when no namespace `{{.Context}} :: {{if .Namespace}}{{.Namespace}}{{else}}default{{end}}` -[go-text-template]: https://golang.org/pkg/text/template/ -[sprig]: https://masterminds.github.io/sprig/ +[templates]: /docs/config-text#templates diff --git a/docs/docs/segment-nbgv.mdx b/docs/docs/segment-nbgv.mdx index 2b0a24b3..7c12da2c 100644 --- a/docs/docs/segment-nbgv.mdx +++ b/docs/docs/segment-nbgv.mdx @@ -27,12 +27,7 @@ The Nerdbank.GitVersioning CLI can be a bit slow causing the prompt to feel slow } ``` -## Properties - -- template: `string` - A go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the -properties below - defaults to `{{ .Version }}` - -## Template Properties +## [Template][templates] Properties - `.Version`: `string` - the current version - `.AssemblyVersion`: `string` - the current assembly version @@ -43,5 +38,4 @@ properties below - defaults to `{{ .Version }}` - `.SimpleVersion`: `string` - the current simple version [nbgv]: https://github.com/dotnet/Nerdbank.GitVersioning -[go-text-template]: https://golang.org/pkg/text/template/ -[sprig]: https://masterminds.github.io/sprig/ +[templates]: /docs/config-text#templates diff --git a/docs/docs/segment-nightscout.md b/docs/docs/segment-nightscout.md index 052e58db..969979fb 100644 --- a/docs/docs/segment-nightscout.md +++ b/docs/docs/segment-nightscout.md @@ -64,12 +64,6 @@ Or display in mmol/l (instead of the default mg/dl) with the following template: - http_timeout: `int` - How long do you want to wait before you want to see your prompt more than your sugar? I figure a half second is a good default - defaults to 500ms -- template: `string` - a go [text/template][go-text-template] template extended - with [sprig][sprig] utilizing the properties below. - See the example above where I added a syringe. - You can change the icon, put the trend elsewhere, add text, however you like! - Make sure your NerdFont has the glyph you want or search for one - at nerdfonts.com - NSCacheTimeout: `int` in minutes - How long do you want your numbers cached? - defaults to 5 min @@ -85,7 +79,7 @@ Or display in mmol/l (instead of the default mg/dl) with the following template: - SingleDownIcon - defaults to ↓ - DoubleDownIcon - defaults to ↓↓ -## Template Properties +## [Template][templates] Properties - .ID: `string` - The internal ID of the object - .Sgv: `int` - Your Serum Glucose Value (your sugar) @@ -100,6 +94,5 @@ Or display in mmol/l (instead of the default mg/dl) with the following template: - .TrendIcon: `string` - By default, this will be something like ↑↑ or ↘ etc but you can override them with any glpyh as seen above -[go-text-template]: https://golang.org/pkg/text/template/ -[sprig]: https://masterminds.github.io/sprig/ +[templates]: /docs/config-text#templates [nightscout]: http://www.nightscout.info/ diff --git a/docs/docs/segment-node.md b/docs/docs/segment-node.md index 5b481ee6..853f09a6 100644 --- a/docs/docs/segment-node.md +++ b/docs/docs/segment-node.md @@ -33,10 +33,8 @@ Display the currently active node version. - fetch_package_manager: `boolean` - define if the current project uses Yarn or NPM - defaults to `false` - yarn_icon: `string` - the icon/text to display when using Yarn - defaults to ` \uF61A` - npm_icon: `string` - the icon/text to display when using NPM - defaults to ` \uE71E` -- template: `string` - A go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the -properties below. Defaults to `{{ .Full }}` -## Template Properties +## [Template][templates] Properties - `.Full`: `string` - the full version - `.Major`: `string` - major number @@ -48,5 +46,4 @@ properties below. Defaults to `{{ .Full }}` - `.PackageManagerIcon`: `string` - the Yarn on NPM icon when setting `fetch_package_manager` to `true` - `.Mismatch`: `boolean` - if the version in `.nvmrc` matches with `.Full` -[go-text-template]: https://golang.org/pkg/text/template/ -[sprig]: https://masterminds.github.io/sprig/ +[templates]: /docs/config-text#templates diff --git a/docs/docs/segment-os.md b/docs/docs/segment-os.md index 98f149a6..f18d5453 100644 --- a/docs/docs/segment-os.md +++ b/docs/docs/segment-os.md @@ -28,8 +28,6 @@ Display OS specific info - defaults to Icon. - macos: `string` - the string to use for macOS - defaults to macOS icon - defaults to `\uF179` - linux: `string` - the icon to use for Linux - defaults to Linux icon - defaults to `\uF17C` - windows: `string` - the icon to use for Windows - defaults to Windows icon - defaults to `\uE62A` -- wsl: `string` - the string/icon to use for WSL - defaults to `WSL` -- wsl_separator: `string` - the string to use for separating WSL from Linux - defaults to ` - ` - display_distro_name: `boolean` - display the distro name or icon (for WSL and Linux) - defaults to `false` - alpine: `string` - the icon to use for Alpine - defaults to Alpine icon - defaults to `\uF300` - aosc: `string` - the icon to use for Aosc - defaults to Aosc icon - defaults to `\uF301` @@ -51,6 +49,8 @@ Display OS specific info - defaults to Icon. - slackware: `string` - the icon to use for Slackware - defaults to Slackware icon - defaults to `\uF319` - ubuntu: `string` - the icon to use for Ubuntu - defaults to Ubuntu icon - defaults to `\uF31b` -## Template Properties +## [Template][templates] Properties - `.OS`: `string` - the OS platform + +[templates]: /docs/config-text#templates diff --git a/docs/docs/segment-owm.md b/docs/docs/segment-owm.md index 4f892ed0..3dee4c5c 100644 --- a/docs/docs/segment-owm.md +++ b/docs/docs/segment-owm.md @@ -1,7 +1,7 @@ --- id: owm title: Open Weather Map -sidebar_label: Open Weather Map +sidebar_label: Open Weather Map --- ## What @@ -12,7 +12,6 @@ Shows the current weather of a given location. You **must** request an API key at the [Open Weather Map](https://openweathermap.org/price) website. The free tier for *Current weather and forecasts collection* is sufficient. - ::: ## Sample Configuration @@ -50,9 +49,11 @@ The free tier for *Current weather and forecasts collection* is sufficient. - template: `string` - A go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the properties below - defaults to `{{.Weather}} ({{.Temperature}}{{.UnitIcon}})` -## Template Properties +## [Template][templates] Properties - `.Weather`: `string` - the current weather icon - `.Temperature`: `string` - the current temperature - `.UnitIcon`: `string` - the current unit icon(based on units property) - `.URL`: `string` - the url of the current api call + +[templates]: /docs/config-text#templates diff --git a/docs/docs/segment-path.md b/docs/docs/segment-path.md index ff14fe75..cdd75953 100644 --- a/docs/docs/segment-path.md +++ b/docs/docs/segment-path.md @@ -38,8 +38,6 @@ Display the current path. - mixed_threshold: `number` - the maximum length of a path segment that will be displayed when using `Mixed` - defaults to `4` - max_depth: `number` - maximum path depth to display before shortening when using `Agnoster Short` - defaults to `1` -- template: `string` - A go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the -properties below. Defaults to `{{ .Path }}` ## Mapped Locations @@ -125,10 +123,9 @@ starts with a symbol or icon. - `__pycache__` will be shortened to `__p` - `➼ folder` will be shortened to `➼ f` -## Template Properties +## [Template][templates] Properties - `.Path`: `string` - the current directory (styled) - `.StackCount`: `int` - the stack count -[go-text-template]: https://golang.org/pkg/text/template/ -[sprig]: https://masterminds.github.io/sprig/ +[templates]: /docs/config-text#templates diff --git a/docs/docs/segment-php.md b/docs/docs/segment-php.md index 47b09fbc..2b1697fd 100644 --- a/docs/docs/segment-php.md +++ b/docs/docs/segment-php.md @@ -27,17 +27,15 @@ Display the currently active php version. ## Properties - home_enabled: `boolean` - display the segment in the HOME folder or not - defaults to `false` -- display_version: `boolean` - display the php version - defaults to `true` +- fetch_version: `boolean` - display the php version - defaults to `true` - display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true` - missing_command_text: `string` - text to display when the command is missing - defaults to empty - display_mode: `string` - determines when the segment is displayed - `always`: the segment is always displayed - `files`: the segment is only displayed when `*.php, composer.json, composer.lock, .php-version` files are present (default) - enable_hyperlink: `bool` - display an hyperlink to the php release notes - defaults to `false` -- template: `string` - A go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the -properties below. Defaults to `{{ .Full }}` -## Template Properties +## [Template][templates] Properties - `.Full`: `string` - the full version - `.Major`: `string` - major number @@ -47,5 +45,4 @@ properties below. Defaults to `{{ .Full }}` - `.BuildMetadata`: `string` - build metadata - `.Error`: `string` - when fetching the version string errors -[go-text-template]: https://golang.org/pkg/text/template/ -[sprig]: https://masterminds.github.io/sprig/ +[templates]: /docs/config-text#templates diff --git a/docs/docs/segment-plastic.md b/docs/docs/segment-plastic.md index 331e062c..f33afa7f 100644 --- a/docs/docs/segment-plastic.md +++ b/docs/docs/segment-plastic.md @@ -45,14 +45,11 @@ Local changes can also be displayed which uses the following syntax (see `.Statu ## Plastic SCM Icon If you want to use the icon of Plastic SCM in the segment, then please help me push the icon in this [issue][fa-issue] -by leaving a like! +by leaving a like! ![icon](https://www.plasticscm.com/images/icon-logo-plasticscm.svg) ## Properties -- template: `string` - A go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the -properties below - defaults to empty. - ### Fetching information As doing multiple `cm` calls can slow down the prompt experience, we do not fetch information by default. @@ -74,12 +71,12 @@ You can set the following property to `true` to enable fetching additional infor - commit_icon: `string` - icon/text to display before the commit context (detached HEAD) - defaults to `\uF417` - tag_icon: `string` - icon/text to display before the tag context - defaults to `\uF412` -## Template Properties +## [Template][templates] Properties - `.Selector`: `string` - the current selector context (branch/changeset/label) - `.Behind`: `bool` - the current workspace is behind and changes are incoming - `.Status`: `PlasticStatus` - changes in the workspace (see below) -- `.MergePending`: `bool` - if a merge is pending and needs to be commited +- `.MergePending`: `bool` - if a merge is pending and needs to be commited (kown issue: when no file is left after a *Change/Delete conflict* merge, the `MergePending` property is not set) ### PlasticStatus @@ -92,6 +89,5 @@ You can set the following property to `true` to enable fetching additional infor - `.Changed`: `boolean` - if the status contains changes or not - `.String`: `string` - a string representation of the changes above -[go-text-template]: https://golang.org/pkg/text/template/ -[sprig]: https://masterminds.github.io/sprig/ +[templates]: /docs/config-text#templates [fa-issue]: https://github.com/FortAwesome/Font-Awesome/issues/18504 diff --git a/docs/docs/segment-posh-git.mdx b/docs/docs/segment-posh-git.mdx index 6db9020d..aa398cab 100644 --- a/docs/docs/segment-posh-git.mdx +++ b/docs/docs/segment-posh-git.mdx @@ -25,4 +25,9 @@ To enable the `posh-git` module, set `$env:POSH_GIT_ENABLED = $true` in your `$P } ``` +## [Template][templates] Properties + +- `.Status`: `string` - the status reported from posh-git + [posh-git]: https://github.com/dahlbyk/posh-git +[templates]: /docs/config-text#templates diff --git a/docs/docs/segment-python.md b/docs/docs/segment-python.md index b15bcd2d..cd179016 100644 --- a/docs/docs/segment-python.md +++ b/docs/docs/segment-python.md @@ -30,7 +30,7 @@ Supports conda, virtualenv and pyenv. - fetch_virtual_env: `boolean` - fetch the name of the virtualenv or not - defaults to `true` - display_default: `boolean` - show the name of the virtualenv when it's default (`system`, `base`) or not - defaults to `true` -- display_version: `boolean` - display the python version - defaults to `true` +- fetch_version: `boolean` - fetch the python version - defaults to `true` - display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true` - missing_command_text: `string` - text to display when the command is missing - defaults to empty - display_mode: `string` - determines when the segment is displayed @@ -39,10 +39,8 @@ or not - defaults to `true` files are present (default) - `environment`: the segment is only displayed when a virtual env is present - `context`: the segment is only displayed when either `environment` or `files` is active -- template: `string` - A go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the -properties below. Defaults to `{{ .Full }}` -## Template Properties +## [Template][templates] Properties - `.Venv`: `string` - the virtual environment name (if present) - `.Full`: `string` - the full version @@ -53,5 +51,4 @@ properties below. Defaults to `{{ .Full }}` - `.BuildMetadata`: `string` - build metadata - `.Error`: `string` - when fetching the version string errors -[go-text-template]: https://golang.org/pkg/text/template/ -[sprig]: https://masterminds.github.io/sprig/ +[templates]: /docs/config-text#templates diff --git a/docs/docs/segment-root.md b/docs/docs/segment-root.md index b7d4833c..b27645a2 100644 --- a/docs/docs/segment-root.md +++ b/docs/docs/segment-root.md @@ -18,11 +18,7 @@ Show when the current user is root or when in an elevated shell (Windows). "foreground": "#111111", "background": "#ffff66", "properties": { - "root_icon": "\uF0E7" + "template": "\uF0E7" } } ``` - -## Properties - -- root_icon: `string` - icon to display in case of root/elevated - defaults to `\uF0E7` diff --git a/docs/docs/segment-ruby.md b/docs/docs/segment-ruby.md index c15e2643..fe5d5395 100644 --- a/docs/docs/segment-ruby.md +++ b/docs/docs/segment-ruby.md @@ -26,16 +26,14 @@ Display the currently active ruby version. ## Properties - home_enabled: `boolean` - display the segment in the HOME folder or not - defaults to `false` -- display_version: `boolean` - display the ruby version - defaults to `true` +- fetch_version: `boolean` - display the ruby version - defaults to `true` - display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true` - missing_command_text: `string` - text to display when the command is missing - defaults to empty - display_mode: `string` - determines when the segment is displayed - `always`: the segment is always displayed - `files`: the segment is only displayed when `*.rb`, `Gemfile` or `Rakefile` files are present (default) -- template: `string` - A go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the -properties below. Defaults to `{{ .Full }}` -## Template Properties +## [Template][templates] Properties - `.Full`: `string` - the full version - `.Major`: `string` - major number @@ -45,5 +43,4 @@ properties below. Defaults to `{{ .Full }}` - `.BuildMetadata`: `string` - build metadata - `.Error`: `string` - when fetching the version string errors -[go-text-template]: https://golang.org/pkg/text/template/ -[sprig]: https://masterminds.github.io/sprig/ +[templates]: /docs/config-text#templates diff --git a/docs/docs/segment-rust.md b/docs/docs/segment-rust.md index 40a1ce56..ee44b1ed 100644 --- a/docs/docs/segment-rust.md +++ b/docs/docs/segment-rust.md @@ -26,16 +26,14 @@ Display the currently active rust version. ## Properties - home_enabled: `boolean` - display the segment in the HOME folder or not - defaults to `false` -- display_version: `boolean` - display the rust version (`rustc --version`) - defaults to `true` +- fetch_version: `boolean` - display the rust version (`rustc --version`) - defaults to `true` - display_error: `boolean` - show the error context when failing to retrieve the version information - defaults to `true` - missing_command_text: `string` - text to display when the command is missing - defaults to empty - display_mode: `string` - determines when the segment is displayed - `always`: the segment is always displayed - `files`: the segment is only displayed when `*.rs`, `Cargo.toml` or `Cargo.lock` files are present (default) -- template: `string` - A go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the -properties below. Defaults to `{{ .Full }}` -## Template Properties +## [Template][templates] Properties - `.Full`: `string` - the full version - `.Major`: `string` - major number @@ -45,5 +43,4 @@ properties below. Defaults to `{{ .Full }}` - `.BuildMetadata`: `string` - build metadata - `.Error`: `string` - when fetching the version string errors -[go-text-template]: https://golang.org/pkg/text/template/ -[sprig]: https://masterminds.github.io/sprig/ +[templates]: /docs/config-text#templates diff --git a/docs/docs/segment-session.md b/docs/docs/segment-session.md index 1575f570..9548affb 100644 --- a/docs/docs/segment-session.md +++ b/docs/docs/segment-session.md @@ -24,17 +24,11 @@ Show the current user and host name. } ``` -## Properties - -- template: `string` - A go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the -properties below. - -## Template Properties +## [Template][templates] Properties - `.UserName`: `string` - the current user's name - `.HostName`: `string` - the current computer's name - `.SSHSession`: `boolean` - active SSH session or not - `.Root`: `boolean` - are you a root/admin user or not -[go-text-template]: https://golang.org/pkg/text/template/ -[sprig]: https://masterminds.github.io/sprig/ +[templates]: /docs/config-text#templates diff --git a/docs/docs/segment-shell.md b/docs/docs/segment-shell.md index 5ae1697b..79850725 100644 --- a/docs/docs/segment-shell.md +++ b/docs/docs/segment-shell.md @@ -28,3 +28,9 @@ Show the current shell name (ZSH, powershell, bash, ...). ## Properties - mapped_shell_names: `object` - custom glyph/text to use in place of specified shell names (case-insensitive) + +## [Template][templates] Properties + +- `.Name`: `string` - the shell name + +[templates]: /docs/config-text#templates diff --git a/docs/docs/segment-spotify.md b/docs/docs/segment-spotify.md index a7960e3a..c8c1b301 100644 --- a/docs/docs/segment-spotify.md +++ b/docs/docs/segment-spotify.md @@ -6,10 +6,10 @@ sidebar_label: Spotify ## What -Show the currently playing song in the Spotify MacOS/Windows client. -On Windows/WSL, only the playing state is supported (no information when paused/stopped). -On macOS, all states are supported (playing/paused/stopped). -**Be aware this can make the prompt a tad bit slower as it needs to get a response from the Spotify player.** +Show the currently playing song in the Spotify MacOS/Windows client. +On Windows/WSL, only the playing state is supported (no information when paused/stopped). +On macOS, all states are supported (playing/paused/stopped). +**Be aware this can make the prompt a tad bit slower as it needs to get a response from the Spotify player.** ## Sample Configuration @@ -24,8 +24,7 @@ On macOS, all states are supported (playing/paused/stopped). "prefix": "\uF9C6 ", "playing_icon": "\uE602 ", "paused_icon": "\uF8E3 ", - "stopped_icon": "\uF04D ", - "track_separator" : " - " + "stopped_icon": "\uF04D " } } ``` @@ -35,4 +34,12 @@ On macOS, all states are supported (playing/paused/stopped). - playing_icon: `string` - text/icon to show when playing - defaults to `\uE602 ` - paused_icon: `string` - text/icon to show when paused - defaults to `\uF8E3 ` - stopped_icon: `string` - text/icon to show when stopped - defaults to `\uF04D ` -- track_separator: `string` - text/icon to put between the artist and song name - defaults to ` - ` + +## [Template][templates] Properties + +- `.Status`: `string` - player status (`playing`, `paused`, `stopped`) +- `.Artist`: `string` - current artist +- `.Track`: `string` - current track +- `.Icon`: `string` - icon (based on `.Status`) + +[templates]: /docs/config-text#templates diff --git a/docs/docs/segment-strava.mdx b/docs/docs/segment-strava.mdx index edea5596..540e647a 100644 --- a/docs/docs/segment-strava.mdx +++ b/docs/docs/segment-strava.mdx @@ -62,8 +62,6 @@ if that color is visible against any of your backgrounds. - refresh_token: `string` - token from Strava login, see login link in section above. It has the following format: `1111111111111111111111111` - expires_in: `int` - the default timeout of the token from the Strava login - http_timeout: `int` - how long do you want to wait before you want to see your prompt more than your strava data? - defaults to 500ms -- template: `string` - a go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the properties below. -See the example above. Make sure your NerdFont has the glyph you want or search for one at nerdfonts.com - CacheTimeout: `int` in minutes - How long do you want your numbers cached? - defaults to 5 min - RideIcon - defaults to `\uf5a2` - RunIcon - defaults to `\ufc0c` @@ -72,7 +70,7 @@ See the example above. Make sure your NerdFont has the glyph you want or search - UnknownActivityIcon - defaults to `\ue213` - enable_hyperlink - display an hyperlink to activities - defaults to `false` -## Template Properties +## [Template][templates] Properties The properties below are available for use in your template @@ -94,7 +92,6 @@ The properties below are available for use in your template Now, go out and have a fun ride or run! -[go-text-template]: https://golang.org/pkg/text/template/ -[sprig]: https://masterminds.github.io/sprig/ +[templates]: /docs/config-text#templates [strava]: http://www.strava.com/ [strava-connect]: https://www.strava.com/oauth/authorize?client_id=76033&response_type=code&redirect_uri=https://ohmyposh.dev/api/auth&approval_prompt=force&scope=read,activity:read diff --git a/docs/docs/sysinfo.md b/docs/docs/segment-sysinfo.md similarity index 84% rename from docs/docs/sysinfo.md rename to docs/docs/segment-sysinfo.md index 22cae13c..c268744b 100644 --- a/docs/docs/sysinfo.md +++ b/docs/docs/segment-sysinfo.md @@ -1,7 +1,7 @@ --- id: sysinfo -title: SysInfo -sidebar_label: SysInfo +title: System Info +sidebar_label: System Info --- ## SysInfo @@ -30,10 +30,8 @@ Display SysInfo. ## Properties - Precision: `int` - The precision used for any float values - defaults to 2 -- template: `string` - A go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the -properties below - defaults to `{{ round .PhysicalPercentUsed .Precision }}> ` -## Template Properties +## [Template][templates] Properties - `.PhysicalTotalMemory`: `int` - is the total of used physical memory - `.PhysicalFreeMemory`: `int` - is the total of free physical memory @@ -47,3 +45,4 @@ properties below - defaults to `{{ round .PhysicalPercentUsed .Precision }}> ` - `.CPU`: `[]struct` - an array of [InfoStat][cpuinfo] object, you can use any property it has e.g. `(index .CPU 0).Cores` [cpuinfo]: https://github.com/shirou/gopsutil/blob/78065a7ce2021f6a78c8d6f586a2683ba501dcec/cpu/cpu.go#L32 +[templates]: /docs/config-text#templates diff --git a/docs/docs/segment-terraform.md b/docs/docs/segment-terraform.md index 8e1be815..eaf08245 100644 --- a/docs/docs/segment-terraform.md +++ b/docs/docs/segment-terraform.md @@ -27,9 +27,8 @@ This requires a terraform binary in your PATH and will only show in directories } ``` -- template: `string` - A go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the -properties below - defaults to `{{ .WorkspaceName }}> ` - -## Template Properties +## [Template][templates] Properties - `.WorkspaceName`: `string` - is the current workspace name + +[templates]: /docs/config-text#templates diff --git a/docs/docs/segment-text.md b/docs/docs/segment-text.md index 609bc66e..21552f38 100644 --- a/docs/docs/segment-text.md +++ b/docs/docs/segment-text.md @@ -35,12 +35,7 @@ New-Alias -Name 'Set-PoshContext' -Value 'Set-EnvVar' -Scope Global -Force ::: -## Properties - -- template: `string` - text/icon to display. Powered by go [text/template][go-text-template] templates extended -with [sprig][sprig] utilizing the properties below. - -## Template Properties +## [Template][templates] Properties - `.Root`: `boolean` - is the current user root/admin or not - `.Path`: `string` - the current working directory @@ -51,5 +46,4 @@ with [sprig][sprig] utilizing the properties below. - `.Env.VarName`: `string` - Any environment variable where `VarName` is the environment variable name [coloring]: /docs/config-colors -[go-text-template]: https://golang.org/pkg/text/template/ -[sprig]: https://masterminds.github.io/sprig/ +[templates]: /docs/config-text#templates diff --git a/docs/docs/segment-time.md b/docs/docs/segment-time.md index 5b5ed1aa..9f4fb14e 100644 --- a/docs/docs/segment-time.md +++ b/docs/docs/segment-time.md @@ -25,14 +25,7 @@ Show the current timestamp. - time_format: `string` - format to use, follows the [golang standard][format] - defaults to `15:04:05` -[format]: https://yourbasic.org/golang/format-parse-string-time-date-example/ - -- template: `string` - A go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the - properties below. Only used when a value is set, making the above properties obsolete. - - example: `{{ now | date \"January 02, 2006 15:04:05 PM\" | lower }}` - -## Template Properties +## [Template][templates] Properties - `.CurrentDate`: `time` - The time to display(testing purpose) @@ -72,5 +65,5 @@ Show the current timestamp. - StampMicro = "Jan _2 15:04:05.000000" - StampNano = "Jan _2 15:04:05.000000000" -[go-text-template]: https://golang.org/pkg/text/template/ -[sprig]: https://masterminds.github.io/sprig/ +[templates]: /docs/config-text#templates +[format]: https://yourbasic.org/golang/format-parse-string-time-date-example/ diff --git a/docs/docs/segment-wakatime.md b/docs/docs/segment-wakatime.md index 4fa65048..b863af32 100644 --- a/docs/docs/segment-wakatime.md +++ b/docs/docs/segment-wakatime.md @@ -39,10 +39,8 @@ The free tier for is sufficient. You'll find the API key in your profile setting works if you can curl it yourself and a result. - defaults to `` - http_timeout: `int` - The default timeout for http request is 20ms. If no segment is shown, try increasing this timeout. - cache_timeout: `int` - The default timeout for request caching is 10m. A value of 0 disables the cache. -- template: `string` - A go [text/template][go-text-template] template extended with [sprig][sprig] utilizing the -properties below - defaults to `{{ secondsRound .CummulativeTotal.Seconds }}` -## Template Properties +## [Template][templates] Properties - `.CummulativeTotal`: `wtTotals` - object holding total tracked time values @@ -53,5 +51,4 @@ properties below - defaults to `{{ secondsRound .CummulativeTotal.Seconds }}` [wt]: https://wakatime.com [wk-summaries]: https://wakatime.com/developers#summaries -[go-text-template]: https://golang.org/pkg/text/template/ -[sprig]: https://masterminds.github.io/sprig/ +[templates]: /docs/config-text#templates diff --git a/docs/docs/segment-wifi.md b/docs/docs/segment-wifi.md index 8e7fef7e..4d9f59f4 100644 --- a/docs/docs/segment-wifi.md +++ b/docs/docs/segment-wifi.md @@ -30,12 +30,7 @@ Currently only supports Windows and WSL. Pull requests for Darwin and Linux supp } ``` -## Properties - -- template: `string` - A go [text/template][go-text-template] extended with [sprig][sprig] using the properties below. -Defaults to `{{ if .Error }}{{ .Error }}{{ else }}\uFAA8 {{ .SSID }} {{ .Signal }}% {{ .ReceiveRate }}Mbps{{ end }}` - -## Template Properties +## [Template][templates] Properties - `.SSID`: `string` - the SSID of the current wifi network - `.RadioType`: `string` - the radio type - _e.g. 802.11ac, 802.11ax, 802.11n, etc._ @@ -45,5 +40,4 @@ Defaults to `{{ if .Error }}{{ .Error }}{{ else }}\uFAA8 {{ .SSID }} {{ .Signal - `.TransmitRate`: `int` - the transmit rate (Mbps) - `.Signal`: `int` - the signal strength (%) -[go-text-template]: https://golang.org/pkg/text/template/ -[sprig]: https://masterminds.github.io/sprig/ +[templates]: /docs/config-text#templates diff --git a/docs/docs/segment-winreg.md b/docs/docs/segment-winreg.md index 426bca72..6e4c870f 100644 --- a/docs/docs/segment-winreg.md +++ b/docs/docs/segment-winreg.md @@ -34,15 +34,12 @@ Supported registry key types: ## Properties -- path: `string` - registry path to the desired key using backslashes and with a valid root HKEY name. +- path: `string` - registry path to the desired key using backslashes and with a valid root HKEY name. Ending path with \ will get the (Default) key from that path. - fallback: `string` - the value to fall back to if no entry is found -- template: `string` - a go [text/template][go-text-template] template extended - with [sprig][sprig] utilizing the properties below. -## Template Properties +## [Template][templates] Properties - .Value: `string` - The result of your query, or fallback if not found. -[go-text-template]: https://golang.org/pkg/text/template/ -[sprig]: https://masterminds.github.io/sprig/ +[templates]: /docs/config-text#templates diff --git a/docs/docs/segment-ytm.md b/docs/docs/segment-ytm.md index a79e41af..e77685be 100644 --- a/docs/docs/segment-ytm.md +++ b/docs/docs/segment-ytm.md @@ -26,8 +26,7 @@ Remote Control password. "prefix": "\uF16A ", "playing_icon": "\uE602 ", "paused_icon": "\uF8E3 ", - "stopped_icon": "\uF04D ", - "track_separator" : " - " + "stopped_icon": "\uF04D " } } ``` @@ -37,5 +36,15 @@ Remote Control password. - playing_icon: `string` - text/icon to show when playing - defaults to `\uE602 ` - paused_icon: `string` - text/icon to show when paused - defaults to `\uF8E3 ` - stopped_icon: `string` - text/icon to show when paused - defaults to `\uF04D ` -- track_separator: `string` - text/icon to put between the artist and song name - defaults to ` - ` - api_url: `string` - the YTMDA Remote Control API URL- defaults to `http://127.0.0.1:9863` + +## [Template][templates] Properties + +- `.Status`: `string` - player status (`playing`, `paused`, `stopped`) +- `.Artist`: `string` - current artist +- `.Track`: `string` - current track +- `.Icon`: `string` - icon (based on `.Status`) + +[templates]: /docs/config-text#templates + +[templates]: /docs/config-text#templates diff --git a/docs/sidebars.js b/docs/sidebars.js index 95b0d003..c9316326 100644 --- a/docs/sidebars.js +++ b/docs/sidebars.js @@ -25,7 +25,7 @@ module.exports = { "config-sample", "config-title", "config-colors", - "config-text-style", + "config-text", "config-transient", "config-tooltips", "config-fonts" diff --git a/src/environment.go b/src/environment.go index 2cedc5c1..779e515a 100644 --- a/src/environment.go +++ b/src/environment.go @@ -558,6 +558,7 @@ func (env *environment) templateCache() *templateCache { Root: env.isRunningAsRoot(), Shell: env.getShellName(), Code: env.lastErrorCode(), + WSL: env.isWsl(), } tmplCache.Env = make(map[string]string) const separator = "=" diff --git a/src/segment_angular.go b/src/segment_angular.go index 149d2452..5fda5e0b 100644 --- a/src/segment_angular.go +++ b/src/segment_angular.go @@ -10,7 +10,11 @@ type angular struct { } func (a *angular) string() string { - return a.language.string() + segmentTemplate := a.language.props.getString(SegmentTemplate, "") + if len(segmentTemplate) == 0 { + return a.language.string() + } + return a.language.renderTemplate(segmentTemplate, a) } func (a *angular) init(props Properties, env Environment) { diff --git a/src/segment_az_functions.go b/src/segment_az_functions.go index de626e61..e810f18b 100644 --- a/src/segment_az_functions.go +++ b/src/segment_az_functions.go @@ -5,7 +5,11 @@ type azfunc struct { } func (az *azfunc) string() string { - return az.language.string() + segmentTemplate := az.language.props.getString(SegmentTemplate, "") + if len(segmentTemplate) == 0 { + return az.language.string() + } + return az.language.renderTemplate(segmentTemplate, az) } func (az *azfunc) init(props Properties, env Environment) { diff --git a/src/segment_command.go b/src/segment_command.go index 6cbcdfc3..de23b5c0 100644 --- a/src/segment_command.go +++ b/src/segment_command.go @@ -5,7 +5,8 @@ import "strings" type command struct { props Properties env Environment - value string + + Output string } const ( @@ -24,9 +25,9 @@ func (c *command) enabled() bool { if strings.Contains(command, "||") { commands := strings.Split(command, "||") for _, cmd := range commands { - output := c.env.runShellCommand(shell, cmd) + output := c.env.runShellCommand(shell, strings.TrimSpace(cmd)) if output != "" { - c.value = output + c.Output = output return true } } @@ -35,17 +36,27 @@ func (c *command) enabled() bool { var output string commands := strings.Split(command, "&&") for _, cmd := range commands { - output += c.env.runShellCommand(shell, cmd) + output += c.env.runShellCommand(shell, strings.TrimSpace(cmd)) } - c.value = output - return c.value != "" + c.Output = output + return c.Output != "" } - c.value = c.env.runShellCommand(shell, command) - return c.value != "" + c.Output = c.env.runShellCommand(shell, strings.TrimSpace(command)) + return c.Output != "" } func (c *command) string() string { - return c.value + segmentTemplate := c.props.getString(SegmentTemplate, "{{.Output}}") + template := &textTemplate{ + Template: segmentTemplate, + Context: c, + Env: c.env, + } + text, err := template.render() + if err != nil { + return err.Error() + } + return text } func (c *command) init(props Properties, env Environment) { diff --git a/src/segment_command_test.go b/src/segment_command_test.go index 66502173..8b496d4f 100644 --- a/src/segment_command_test.go +++ b/src/segment_command_test.go @@ -1,5 +1,3 @@ -//go:build !windows - package main import ( @@ -9,11 +7,10 @@ import ( ) func TestExecuteCommand(t *testing.T) { - env := &environment{} - debug := false - env.init(&args{ - Debug: &debug, - }) + env := new(MockedEnvironment) + env.On("hasCommand", "bash").Return(true) + env.On("runShellCommand", "bash", "echo hello").Return("hello") + env.onTemplate() props := properties{ Command: "echo hello", } @@ -27,11 +24,12 @@ func TestExecuteCommand(t *testing.T) { } func TestExecuteMultipleCommandsOrFirst(t *testing.T) { - env := &environment{} - debug := false - env.init(&args{ - Debug: &debug, - }) + env := new(MockedEnvironment) + env.On("hasCommand", "bash").Return(true) + env.On("runShellCommand", "bash", "exit 1").Return("") + env.On("runShellCommand", "bash", "echo hello").Return("hello") + env.On("runShellCommand", "bash", "exit 1 || echo hello").Return("hello") + env.onTemplate() props := properties{ Command: "exit 1 || echo hello", } @@ -45,11 +43,11 @@ func TestExecuteMultipleCommandsOrFirst(t *testing.T) { } func TestExecuteMultipleCommandsOrSecond(t *testing.T) { - env := &environment{} - debug := false - env.init(&args{ - Debug: &debug, - }) + env := new(MockedEnvironment) + env.On("hasCommand", "bash").Return(true) + env.On("runShellCommand", "bash", "echo hello").Return("hello") + env.On("runShellCommand", "bash", "echo world").Return("world") + env.onTemplate() props := properties{ Command: "echo hello || echo world", } @@ -63,11 +61,11 @@ func TestExecuteMultipleCommandsOrSecond(t *testing.T) { } func TestExecuteMultipleCommandsAnd(t *testing.T) { - env := &environment{} - debug := false - env.init(&args{ - Debug: &debug, - }) + env := new(MockedEnvironment) + env.On("hasCommand", "bash").Return(true) + env.On("runShellCommand", "bash", "echo hello").Return("hello") + env.On("runShellCommand", "bash", "echo world").Return("world") + env.onTemplate() props := properties{ Command: "echo hello && echo world", } @@ -81,11 +79,10 @@ func TestExecuteMultipleCommandsAnd(t *testing.T) { } func TestExecuteSingleCommandEmpty(t *testing.T) { - env := &environment{} - debug := false - env.init(&args{ - Debug: &debug, - }) + env := new(MockedEnvironment) + env.On("hasCommand", "bash").Return(true) + env.On("runShellCommand", "bash", "").Return("") + env.onTemplate() props := properties{ Command: "", } @@ -98,11 +95,10 @@ func TestExecuteSingleCommandEmpty(t *testing.T) { } func TestExecuteSingleCommandNoCommandProperty(t *testing.T) { - env := &environment{} - debug := false - env.init(&args{ - Debug: &debug, - }) + env := new(MockedEnvironment) + env.On("hasCommand", "bash").Return(true) + env.On("runShellCommand", "bash", "echo no command specified").Return("no command specified") + env.onTemplate() var props properties c := &command{ props: props, @@ -110,15 +106,14 @@ func TestExecuteSingleCommandNoCommandProperty(t *testing.T) { } enabled := c.enabled() assert.True(t, enabled) - assert.Equal(t, "no command specified", c.value) + assert.Equal(t, "no command specified", c.Output) } func TestExecuteMultipleCommandsAndDisabled(t *testing.T) { - env := &environment{} - debug := false - env.init(&args{ - Debug: &debug, - }) + env := new(MockedEnvironment) + env.On("hasCommand", "bash").Return(true) + env.On("runShellCommand", "bash", "echo").Return("") + env.onTemplate() props := properties{ Command: "echo && echo", } @@ -131,11 +126,11 @@ func TestExecuteMultipleCommandsAndDisabled(t *testing.T) { } func TestExecuteMultipleCommandsOrDisabled(t *testing.T) { - env := &environment{} - debug := false - env.init(&args{ - Debug: &debug, - }) + env := new(MockedEnvironment) + env.On("hasCommand", "bash").Return(true) + env.On("runShellCommand", "bash", "echo").Return("") + env.On("runShellCommand", "bash", "echo|| echo").Return("") + env.onTemplate() props := properties{ Command: "echo|| echo", } diff --git a/src/segment_crystal.go b/src/segment_crystal.go index cf71b6b9..ca22cc6c 100644 --- a/src/segment_crystal.go +++ b/src/segment_crystal.go @@ -5,7 +5,11 @@ type crystal struct { } func (c *crystal) string() string { - return c.language.string() + segmentTemplate := c.language.props.getString(SegmentTemplate, "") + if len(segmentTemplate) == 0 { + return c.language.string() + } + return c.language.renderTemplate(segmentTemplate, c) } func (c *crystal) init(props Properties, env Environment) { diff --git a/src/segment_dart.go b/src/segment_dart.go index ebff79dc..968ff191 100644 --- a/src/segment_dart.go +++ b/src/segment_dart.go @@ -5,7 +5,11 @@ type dart struct { } func (d *dart) string() string { - return d.language.string() + segmentTemplate := d.language.props.getString(SegmentTemplate, "") + if len(segmentTemplate) == 0 { + return d.language.string() + } + return d.language.renderTemplate(segmentTemplate, d) } func (d *dart) init(props Properties, env Environment) { diff --git a/src/segment_deprecated.go b/src/segment_deprecated.go index 54ec96cb..c38e45d5 100644 --- a/src/segment_deprecated.go +++ b/src/segment_deprecated.go @@ -181,13 +181,14 @@ const ( func (e *exit) deprecatedString() string { colorBackground := e.props.getBool(ColorBackground, false) - if e.code != 0 && !colorBackground { + code := e.env.lastErrorCode() + if code != 0 && !colorBackground { e.props.set(ForegroundOverride, e.props.getColor(ErrorColor, e.props.getColor(ForegroundOverride, ""))) } - if e.code != 0 && colorBackground { + if code != 0 && colorBackground { e.props.set(BackgroundOverride, e.props.getColor(ErrorColor, e.props.getColor(BackgroundOverride, ""))) } - if e.code == 0 { + if code == 0 { return e.props.getString(SuccessIcon, "") } errorIcon := e.props.getString(ErrorIcon, "") @@ -195,7 +196,7 @@ func (e *exit) deprecatedString() string { return errorIcon } if e.props.getBool(AlwaysNumeric, false) { - return fmt.Sprintf("%s%d", errorIcon, e.code) + return fmt.Sprintf("%s%d", errorIcon, code) } return fmt.Sprintf("%s%s", errorIcon, e.Text) } @@ -297,7 +298,7 @@ func (s *session) legacyEnabled() bool { return true } -func (s *session) getFormattedText() string { +func (s *session) legacyString() string { separator := "" if s.props.getBool(DisplayHost, true) && s.props.getBool(DisplayUser, true) { separator = s.props.getString(UserInfoSeparator, "@") @@ -336,17 +337,9 @@ func (l *language) string() string { if !l.props.getOneOfBool(FetchVersion, DisplayVersion, true) { return "" } - - err := l.setVersion() - if err != nil { - l.Error = err.Error() - } displayError := l.props.getBool(DisplayError, true) - if err != nil && displayError { - return err.Error() - } - if err != nil { - return "" + if len(l.Error) != 0 && displayError { + return l.Error } segmentTemplate := l.props.getString(SegmentTemplate, "{{ .Full }}") @@ -458,3 +451,11 @@ func (e *envvar) init(props Properties, env Environment) { e.props = props e.env = env } + +// Dotnet + +const ( + // UnsupportedDotnetVersionIcon is displayed when the dotnet version in + // the current folder isn't supported by the installed dotnet SDK set. + UnsupportedDotnetVersionIcon Property = "unsupported_version_icon" +) diff --git a/src/segment_deprecated_test.go b/src/segment_deprecated_test.go index 3475b8e3..2e249528 100644 --- a/src/segment_deprecated_test.go +++ b/src/segment_deprecated_test.go @@ -2,6 +2,7 @@ package main import ( "errors" + "fmt" "testing" "github.com/distatus/battery" @@ -271,18 +272,26 @@ func TestStatusColorsWithoutDisplayStatus(t *testing.T) { status := "## main...origin/main [ahead 33]\n M myfile" env := new(MockedEnvironment) env.On("isWsl").Return(false) + env.On("inWSLSharedDrive").Return(false) env.On("getRuntimeGOOS").Return("unix") - env.On("hasFolder", "/rebase-merge").Return(false) - env.On("hasFolder", "/rebase-apply").Return(false) - env.On("hasFolder", "/sequencer").Return(false) - env.On("getFileContent", "/HEAD").Return(status) - env.On("hasFilesInDir", "", "CHERRY_PICK_HEAD").Return(false) - env.On("hasFilesInDir", "", "REVERT_HEAD").Return(false) - env.On("hasFilesInDir", "", "MERGE_MSG").Return(false) - env.On("hasFilesInDir", "", "MERGE_HEAD").Return(false) - env.On("hasFilesInDir", "", "sequencer/todo").Return(false) - env.mockGitCommand("", "describe", "--tags", "--exact-match") - env.mockGitCommand(status, "status", "-unormal", "--branch", "--porcelain=2") + env.On("hasCommand", "git").Return(true) + fileInfo := &fileInfo{ + path: "/dir/hello", + parentFolder: "/dir", + isDir: true, + } + env.On("hasParentFilePath", ".git").Return(fileInfo, nil) + env.On("getFileContent", fmt.Sprintf("%s/HEAD", fileInfo.path)).Return("") + env.mockGitCommand(fileInfo.path, "", "describe", "--tags", "--exact-match") + env.mockGitCommand(fileInfo.path, status, "status", "-unormal", "--branch", "--porcelain=2") + env.On("hasFolder", fmt.Sprintf("%s/rebase-merge", fileInfo.path)).Return(false) + env.On("hasFolder", fmt.Sprintf("%s/rebase-apply", fileInfo.path)).Return(false) + env.On("hasFilesInDir", fileInfo.path, "CHERRY_PICK_HEAD").Return(false) + env.On("hasFilesInDir", fileInfo.path, "REVERT_HEAD").Return(false) + env.On("hasFilesInDir", fileInfo.path, "MERGE_MSG").Return(false) + env.On("hasFilesInDir", fileInfo.path, "MERGE_HEAD").Return(false) + env.On("hasFilesInDir", fileInfo.path, "sequencer/todo").Return(false) + props := properties{ DisplayStatus: false, StatusColorsEnabled: true, @@ -297,6 +306,7 @@ func TestStatusColorsWithoutDisplayStatus(t *testing.T) { } g.Working = &GitStatus{} g.Staging = &GitStatus{} + _ = g.enabled() g.string() assert.Equal(t, expected, g.props.getColor(BackgroundOverride, "")) } @@ -335,7 +345,8 @@ func TestExitWriterDeprecatedString(t *testing.T) { env: env, props: props, } - assert.Equal(t, tc.Expected, e.string()) + _ = e.enabled() + assert.Equal(t, tc.Expected, e.deprecatedString()) } } diff --git a/src/segment_dotnet.go b/src/segment_dotnet.go index 2a5ce7a5..bd11d9bb 100644 --- a/src/segment_dotnet.go +++ b/src/segment_dotnet.go @@ -2,23 +2,19 @@ package main type dotnet struct { language + + Unsupported bool } -const ( - // UnsupportedDotnetVersionIcon is displayed when the dotnet version in - // the current folder isn't supported by the installed dotnet SDK set. - UnsupportedDotnetVersionIcon Property = "unsupported_version_icon" -) - func (d *dotnet) string() string { - version := d.language.string() - - exitCode := d.language.exitCode - if exitCode == dotnetExitCode { + segmentTemplate := d.language.props.getString(SegmentTemplate, "") + if len(segmentTemplate) != 0 { + return d.language.renderTemplate(segmentTemplate, d) + } + if d.Unsupported { return d.language.props.getString(UnsupportedDotnetVersionIcon, "\uf071 ") } - - return version + return d.language.string() } func (d *dotnet) init(props Properties, env Environment) { @@ -39,5 +35,10 @@ func (d *dotnet) init(props Properties, env Environment) { } func (d *dotnet) enabled() bool { - return d.language.enabled() + enabled := d.language.enabled() + if !enabled { + return false + } + d.Unsupported = d.language.exitCode == dotnetExitCode + return true } diff --git a/src/segment_executiontime.go b/src/segment_executiontime.go index aabe07cc..156df26f 100644 --- a/src/segment_executiontime.go +++ b/src/segment_executiontime.go @@ -60,7 +60,17 @@ func (t *executiontime) enabled() bool { } func (t *executiontime) string() string { - return t.FormattedMs + segmentTemplate := t.props.getString(SegmentTemplate, "{{.FormattedMs}}") + template := &textTemplate{ + Template: segmentTemplate, + Context: t, + Env: t.env, + } + text, err := template.render() + if err != nil { + return err.Error() + } + return text } func (t *executiontime) init(props Properties, env Environment) { diff --git a/src/segment_exit.go b/src/segment_exit.go index 71dbe3ed..4052669d 100644 --- a/src/segment_exit.go +++ b/src/segment_exit.go @@ -6,11 +6,11 @@ type exit struct { props Properties env Environment - code int Text string } func (e *exit) enabled() bool { + e.Text = e.getMeaningFromExitCode(e.env.lastErrorCode()) if e.props.getBool(AlwaysEnabled, false) { return true } @@ -18,17 +18,6 @@ func (e *exit) enabled() bool { } func (e *exit) string() string { - return e.getFormattedText() -} - -func (e *exit) init(props Properties, env Environment) { - e.props = props - e.env = env -} - -func (e *exit) getFormattedText() string { - e.code = e.env.lastErrorCode() - e.Text = e.getMeaningFromExitCode() segmentTemplate := e.props.getString(SegmentTemplate, "") if len(segmentTemplate) == 0 { return e.deprecatedString() @@ -45,8 +34,13 @@ func (e *exit) getFormattedText() string { return text } -func (e *exit) getMeaningFromExitCode() string { - switch e.code { +func (e *exit) init(props Properties, env Environment) { + e.props = props + e.env = env +} + +func (e *exit) getMeaningFromExitCode(code int) string { + switch code { case 1: return "ERROR" case 2: @@ -100,6 +94,6 @@ func (e *exit) getMeaningFromExitCode() string { case 128 + 22: return "SIGTTOU" default: - return strconv.Itoa(e.code) + return strconv.Itoa(code) } } diff --git a/src/segment_exit_test.go b/src/segment_exit_test.go index f8e39249..8347bf48 100644 --- a/src/segment_exit_test.go +++ b/src/segment_exit_test.go @@ -59,8 +59,7 @@ func TestGetMeaningFromExitCode(t *testing.T) { errorMap[7000] = "7000" for exitcode, want := range errorMap { e := &exit{} - e.code = exitcode - assert.Equal(t, want, e.getMeaningFromExitCode()) + assert.Equal(t, want, e.getMeaningFromExitCode(exitcode)) } } diff --git a/src/segment_git.go b/src/segment_git.go index 409c2341..df238797 100644 --- a/src/segment_git.go +++ b/src/segment_git.go @@ -105,6 +105,35 @@ const ( ) func (g *git) enabled() bool { + if !g.shouldDisplay() { + return false + } + statusColorsEnabled := g.props.getBool(StatusColorsEnabled, false) + displayStatus := g.props.getOneOfBool(FetchStatus, DisplayStatus, false) + if !displayStatus { + g.setPrettyHEADName() + } + if displayStatus || statusColorsEnabled { + g.setGitStatus() + g.setGitHEADContext() + g.setBranchStatus() + } else { + g.Working = &GitStatus{} + g.Staging = &GitStatus{} + } + if g.Upstream != "" && g.props.getOneOfBool(FetchUpstreamIcon, DisplayUpstreamIcon, false) { + g.UpstreamIcon = g.getUpstreamIcon() + } + if g.props.getOneOfBool(FetchStashCount, DisplayStashCount, false) { + g.StashCount = g.getStashContext() + } + if g.props.getOneOfBool(FetchWorktreeCount, DisplayWorktreeCount, false) { + g.WorktreeCount = g.getWorktreeContext() + } + return true +} + +func (g *git) shouldDisplay() bool { // when in wsl/wsl2 and in a windows shared folder // we must use git.exe and convert paths accordingly // for worktrees, stashes, and path to work @@ -162,36 +191,13 @@ func (g *git) enabled() bool { } func (g *git) string() string { - statusColorsEnabled := g.props.getBool(StatusColorsEnabled, false) - displayStatus := g.props.getOneOfBool(FetchStatus, DisplayStatus, false) - if !displayStatus { - g.setPrettyHEADName() - } - if displayStatus || statusColorsEnabled { - g.setGitStatus() - g.setGitHEADContext() - g.setBranchStatus() - } else { - g.Working = &GitStatus{} - g.Staging = &GitStatus{} - } - if g.Upstream != "" && g.props.getOneOfBool(FetchUpstreamIcon, DisplayUpstreamIcon, false) { - g.UpstreamIcon = g.getUpstreamIcon() - } - if g.props.getOneOfBool(FetchStashCount, DisplayStashCount, false) { - g.StashCount = g.getStashContext() - } - if g.props.getOneOfBool(FetchWorktreeCount, DisplayWorktreeCount, false) { - g.WorktreeCount = g.getWorktreeContext() - } // use template if available segmentTemplate := g.props.getString(SegmentTemplate, "") if len(segmentTemplate) > 0 { return g.templateString(segmentTemplate) } // legacy render string if no template - // remove this for 6.0 - return g.deprecatedString(statusColorsEnabled) + return g.deprecatedString(g.props.getBool(StatusColorsEnabled, false)) } func (g *git) templateString(segmentTemplate string) string { diff --git a/src/segment_git_test.go b/src/segment_git_test.go index 2af2bb0c..c4acf72b 100644 --- a/src/segment_git_test.go +++ b/src/segment_git_test.go @@ -29,16 +29,18 @@ func TestEnabledGitNotFound(t *testing.T) { } func TestEnabledInWorkingDirectory(t *testing.T) { - env := new(MockedEnvironment) - env.On("inWSLSharedDrive").Return(false) - env.On("hasCommand", "git").Return(true) - env.On("getRuntimeGOOS").Return("") - env.On("isWsl").Return(false) fileInfo := &fileInfo{ path: "/dir/hello", parentFolder: "/dir", isDir: true, } + env := new(MockedEnvironment) + env.On("inWSLSharedDrive").Return(false) + env.On("hasCommand", "git").Return(true) + env.On("getRuntimeGOOS").Return("") + env.On("getFileContent", "/dir/hello/HEAD").Return("") + env.mockGitCommand(fileInfo.path, "", "describe", "--tags", "--exact-match") + env.On("isWsl").Return(false) env.On("hasParentFilePath", ".git").Return(fileInfo, nil) g := &git{ scm: scm{ @@ -61,6 +63,8 @@ func TestEnabledInWorkingTree(t *testing.T) { parentFolder: "/dev/folder_worktree", isDir: false, } + env.On("getFileContent", "/dev/real_folder/.git/worktrees/folder_worktree/HEAD").Return("") + env.mockGitCommand(fileInfo.parentFolder, "", "describe", "--tags", "--exact-match") env.On("hasParentFilePath", ".git").Return(fileInfo, nil) env.On("getFileContent", "/dev/folder_worktree/.git").Return("gitdir: /dev/real_folder/.git/worktrees/folder_worktree") env.On("getFileContent", "/dev/real_folder/.git/worktrees/folder_worktree/gitdir").Return("/dev/folder_worktree.git\n") @@ -86,6 +90,8 @@ func TestEnabledInSubmodule(t *testing.T) { parentFolder: "/dev/parent/test-submodule", isDir: false, } + env.On("getFileContent", "/dev/parent/test-submodule/../.git/modules/test-submodule/HEAD").Return("") + env.mockGitCommand("/dev/parent/test-submodule/../.git/modules/test-submodule", "", "describe", "--tags", "--exact-match") env.On("hasParentFilePath", ".git").Return(fileInfo, nil) env.On("getFileContent", "/dev/parent/test-submodule/.git").Return("gitdir: ../.git/modules/test-submodule") env.On("getFileContent", "/dev/parent/.git/modules/test-submodule").Return("/dev/folder_worktree.git\n") @@ -119,8 +125,8 @@ func TestGetGitOutputForCommand(t *testing.T) { assert.Equal(t, want, got) } -func (m *MockedEnvironment) mockGitCommand(returnValue string, args ...string) { - args = append([]string{"-C", "", "--no-optional-locks", "-c", "core.quotepath=false", "-c", "color.status=false"}, args...) +func (m *MockedEnvironment) mockGitCommand(dir, returnValue string, args ...string) { + args = append([]string{"-C", dir, "--no-optional-locks", "-c", "core.quotepath=false", "-c", "color.status=false"}, args...) m.On("runCommand", "git", args).Return(returnValue, nil) } @@ -231,9 +237,9 @@ func TestSetGitHEADContextClean(t *testing.T) { env.On("inWSLSharedDrive").Return(false) env.On("getRuntimeGOOS").Return("unix") env.On("isWsl").Return(false) - env.mockGitCommand("", "describe", "--tags", "--exact-match") - env.mockGitCommand(tc.Theirs, "name-rev", "--name-only", "--exclude=tags/*", tc.Theirs) - env.mockGitCommand(tc.Ours, "name-rev", "--name-only", "--exclude=tags/*", tc.Ours) + env.mockGitCommand("", "", "describe", "--tags", "--exact-match") + env.mockGitCommand("", tc.Theirs, "name-rev", "--name-only", "--exclude=tags/*", tc.Theirs) + env.mockGitCommand("", tc.Ours, "name-rev", "--name-only", "--exclude=tags/*", tc.Ours) // rebase merge env.On("hasFolder", "/rebase-merge").Return(tc.RebaseMerge) env.On("getFileContent", "/rebase-merge/head-name").Return(tc.Ours) @@ -299,7 +305,7 @@ func TestSetPrettyHEADName(t *testing.T) { env.On("getFileContent", "/HEAD").Return(tc.HEAD) env.On("getRuntimeGOOS").Return("unix") env.On("isWsl").Return(false) - env.mockGitCommand(tc.Tag, "describe", "--tags", "--exact-match") + env.mockGitCommand("", tc.Tag, "describe", "--tags", "--exact-match") g := &git{ scm: scm{ env: env, @@ -416,7 +422,7 @@ func TestSetGitStatus(t *testing.T) { env := new(MockedEnvironment) env.On("getRuntimeGOOS").Return("unix") env.On("isWsl").Return(false) - env.mockGitCommand(strings.ReplaceAll(tc.Output, "\t", ""), "status", "-unormal", "--branch", "--porcelain=2") + env.mockGitCommand("", strings.ReplaceAll(tc.Output, "\t", ""), "status", "-unormal", "--branch", "--porcelain=2") g := &git{ scm: scm{ env: env, diff --git a/src/segment_golang.go b/src/segment_golang.go index de6e9dc5..3ab7574e 100644 --- a/src/segment_golang.go +++ b/src/segment_golang.go @@ -13,7 +13,11 @@ const ( ) func (g *golang) string() string { - return g.language.string() + segmentTemplate := g.language.props.getString(SegmentTemplate, "") + if len(segmentTemplate) == 0 { + return g.language.string() + } + return g.language.renderTemplate(segmentTemplate, g) } func (g *golang) init(props Properties, env Environment) { diff --git a/src/segment_java.go b/src/segment_java.go index f19f1856..72928f10 100644 --- a/src/segment_java.go +++ b/src/segment_java.go @@ -7,7 +7,11 @@ type java struct { } func (j *java) string() string { - return j.language.string() + segmentTemplate := j.language.props.getString(SegmentTemplate, "") + if len(segmentTemplate) == 0 { + return j.language.string() + } + return j.language.renderTemplate(segmentTemplate, j) } func (j *java) init(props Properties, env Environment) { diff --git a/src/segment_julia.go b/src/segment_julia.go index 30233970..ad6ce24a 100644 --- a/src/segment_julia.go +++ b/src/segment_julia.go @@ -5,7 +5,11 @@ type julia struct { } func (j *julia) string() string { - return j.language.string() + segmentTemplate := j.language.props.getString(SegmentTemplate, "") + if len(segmentTemplate) == 0 { + return j.language.string() + } + return j.language.renderTemplate(segmentTemplate, j) } func (j *julia) init(props Properties, env Environment) { diff --git a/src/segment_language.go b/src/segment_language.go index 396a2b19..4244971f 100644 --- a/src/segment_language.go +++ b/src/segment_language.go @@ -84,13 +84,6 @@ const ( ) func (l *language) renderTemplate(segmentTemplate string, context SegmentWriter) string { - if l.props.getBool(FetchVersion, true) { - err := l.setVersion() - if err != nil { - l.Error = err.Error() - } - } - template := &textTemplate{ Template: segmentTemplate, Context: context, @@ -101,6 +94,7 @@ func (l *language) renderTemplate(segmentTemplate string, context SegmentWriter) return err.Error() } + // TODO: this needs to be removed or refactored if !l.props.getBool(EnableHyperlink, false) { return text } @@ -124,31 +118,40 @@ func (l *language) renderTemplate(segmentTemplate string, context SegmentWriter) func (l *language) enabled() bool { // override default extensions if needed l.extensions = l.props.getStringArray(LanguageExtensions, l.extensions) - inHomeDir := func() bool { return l.env.pwd() == l.env.homeDir() } + var enabled bool homeEnabled := l.props.getBool(HomeEnabled, l.homeEnabled) if inHomeDir() && !homeEnabled { - return false + enabled = false + } else { + // set default mode when not set + if len(l.displayMode) == 0 { + l.displayMode = l.props.getString(DisplayMode, DisplayModeFiles) + } + l.loadLanguageContext() + switch l.displayMode { + case DisplayModeAlways: + enabled = true + case DisplayModeEnvironment: + enabled = l.inLanguageContext() + case DisplayModeFiles: + enabled = l.hasLanguageFiles() + case DisplayModeContext: + fallthrough + default: + enabled = l.hasLanguageFiles() || l.inLanguageContext() + } } - // set default mode when not set - if len(l.displayMode) == 0 { - l.displayMode = l.props.getString(DisplayMode, DisplayModeFiles) + if !enabled || !l.props.getOneOfBool(FetchVersion, DisplayVersion, true) { + return enabled } - l.loadLanguageContext() - switch l.displayMode { - case DisplayModeAlways: - return true - case DisplayModeEnvironment: - return l.inLanguageContext() - case DisplayModeFiles: - return l.hasLanguageFiles() - case DisplayModeContext: - fallthrough - default: - return l.hasLanguageFiles() || l.inLanguageContext() + err := l.setVersion() + if err != nil { + l.Error = err.Error() } + return enabled } // hasLanguageFiles will return true at least one file matching the extensions is found diff --git a/src/segment_os.go b/src/segment_os.go index 19d0186e..a5b714fe 100644 --- a/src/segment_os.go +++ b/src/segment_os.go @@ -1,14 +1,10 @@ package main -import ( - "fmt" -) - type osInfo struct { props Properties env Environment - os string + Icon string } const ( @@ -18,10 +14,6 @@ const ( Linux Property = "linux" // Windows the string/icon to use for windows Windows Property = "windows" - // WSL the string/icon to use for WSL - WSL Property = "wsl" - // WSLSeparator shows between WSL and Linux properties when WSL is detected - WSLSeparator Property = "wsl_separator" // Alpine the string/icon to use for Alpine Alpine Property = "alpine" // Aosc the string/icon to use for Aosc @@ -65,41 +57,41 @@ const ( ) func (n *osInfo) enabled() bool { + goos := n.env.getRuntimeGOOS() + switch goos { + case windowsPlatform: + n.Icon = n.props.getString(Windows, "\uE62A") + case darwinPlatform: + n.Icon = n.props.getString(MacOS, "\uF179") + case linuxPlatform: + platform := n.env.getPlatform() + displayDistroName := n.props.getBool(DisplayDistroName, false) + if displayDistroName { + n.Icon = platform + break + } + n.Icon = n.getDistroIcon(platform) + default: + n.Icon = goos + } return true } func (n *osInfo) string() string { - goos := n.env.getRuntimeGOOS() - switch goos { - case windowsPlatform: - n.os = windowsPlatform - return n.props.getString(Windows, "\uE62A") - case darwinPlatform: - n.os = darwinPlatform - return n.props.getString(MacOS, "\uF179") - case linuxPlatform: - n.os = n.env.getPlatform() - if !n.env.isWsl() { - return n.getDistroName(n.os, "") - } - return fmt.Sprintf("%s%s%s", - n.props.getString(WSL, "WSL"), - n.props.getString(WSLSeparator, " - "), - n.getDistroName(n.os, n.os)) - default: - n.os = goos - return goos + segmentTemplate := n.props.getString(SegmentTemplate, "{{ if .WSL }}WSL at {{ end }}{{.Icon}}") + template := &textTemplate{ + Template: segmentTemplate, + Context: n, + Env: n.env, } + text, err := template.render() + if err != nil { + return err.Error() + } + return text } -func (n *osInfo) getDistroName(distro, defaultName string) string { - displayDistroName := n.props.getBool(DisplayDistroName, false) - if displayDistroName && len(defaultName) > 0 { - return defaultName - } - if displayDistroName { - return distro - } +func (n *osInfo) getDistroIcon(distro string) string { switch distro { case "alpine": return n.props.getString(Alpine, "\uF300") diff --git a/src/segment_os_test.go b/src/segment_os_test.go index a2292da0..2bd85f2b 100644 --- a/src/segment_os_test.go +++ b/src/segment_os_test.go @@ -62,23 +62,20 @@ func TestOSInfo(t *testing.T) { for _, tc := range cases { env := new(MockedEnvironment) env.On("getRuntimeGOOS").Return(tc.GOOS) - env.On("isWsl").Return(tc.IsWSL) env.On("getPlatform").Return(tc.Platform) + env.On("templateCache").Return(&templateCache{ + Env: make(map[string]string), + WSL: tc.IsWSL, + }) osInfo := &osInfo{ env: env, props: properties{ - WSL: "WSL", - WSLSeparator: " at ", DisplayDistroName: tc.DisplayDistroName, Windows: "windows", MacOS: "darwin", }, } + _ = osInfo.enabled() assert.Equal(t, tc.ExpectedString, osInfo.string(), tc.Case) - if tc.Platform != "" { - assert.Equal(t, tc.Platform, osInfo.os, tc.Case) - } else { - assert.Equal(t, tc.GOOS, osInfo.os, tc.Case) - } } } diff --git a/src/segment_owm.go b/src/segment_owm.go index 6ded8cda..fd6ed467 100644 --- a/src/segment_owm.go +++ b/src/segment_owm.go @@ -51,17 +51,6 @@ func (d *owm) enabled() bool { } func (d *owm) string() string { - d.UnitIcon = "\ue33e" - switch d.units { - case "imperial": - d.UnitIcon = "°F" // \ue341" - case "metric": - d.UnitIcon = "°C" // \ue339" - case "": - fallthrough - case "standard": - d.UnitIcon = "°K" // \ufa05" - } segmentTemplate := d.props.getString(SegmentTemplate, "{{.Weather}} ({{.Temperature}}{{.UnitIcon}})") template := &textTemplate{ Template: segmentTemplate, @@ -72,7 +61,6 @@ func (d *owm) string() string { if err != nil { return err.Error() } - return text } @@ -118,7 +106,6 @@ func (d *owm) getResult() (*owmDataResponse, error) { func (d *owm) setStatus() error { units := d.props.getString(Units, "standard") - q, err := d.getResult() if err != nil { return err @@ -170,6 +157,17 @@ func (d *owm) setStatus() error { } d.Weather = icon d.units = units + d.UnitIcon = "\ue33e" + switch d.units { + case "imperial": + d.UnitIcon = "°F" // \ue341" + case "metric": + d.UnitIcon = "°C" // \ue339" + case "": + fallthrough + case "standard": + d.UnitIcon = "°K" // \ufa05" + } return nil } diff --git a/src/segment_path.go b/src/segment_path.go index 7dfda3fe..0a2d33fb 100644 --- a/src/segment_path.go +++ b/src/segment_path.go @@ -54,10 +54,6 @@ const ( ) func (pt *path) enabled() bool { - return true -} - -func (pt *path) string() string { pt.pwd = pt.env.pwd() switch style := pt.props.getString(Style, Agnoster); style { case Agnoster: @@ -80,7 +76,7 @@ func (pt *path) string() string { case Folder: pt.Path = pt.getFolderPath() default: - return fmt.Sprintf("Path style: %s is not available", style) + pt.Path = fmt.Sprintf("Path style: %s is not available", style) } pt.Path = pt.formatWindowsDrive(pt.Path) if pt.props.getBool(EnableHyperlink, false) { @@ -92,6 +88,10 @@ func (pt *path) string() string { } pt.StackCount = pt.env.stackCount() + return true +} + +func (pt *path) string() string { segmentTemplate := pt.props.getString(SegmentTemplate, "{{ .Path }}") template := &textTemplate{ Template: segmentTemplate, diff --git a/src/segment_path_test.go b/src/segment_path_test.go index 6582adf3..21d89bec 100644 --- a/src/segment_path_test.go +++ b/src/segment_path_test.go @@ -443,6 +443,7 @@ func TestAgnosterPathStyles(t *testing.T) { SegmentTemplate: "{{ .Path }}", }, } + _ = path.enabled() got := path.string() assert.Equal(t, tc.Expected, got) } @@ -572,6 +573,7 @@ func TestGetFullPath(t *testing.T) { env: env, props: props, } + _ = path.enabled() got := path.string() assert.Equal(t, tc.Expected, got) } diff --git a/src/segment_php.go b/src/segment_php.go index 1f8127e9..f55d1fac 100644 --- a/src/segment_php.go +++ b/src/segment_php.go @@ -4,12 +4,16 @@ type php struct { language } -func (n *php) string() string { - return n.language.string() +func (p *php) string() string { + segmentTemplate := p.language.props.getString(SegmentTemplate, "") + if len(segmentTemplate) == 0 { + return p.language.string() + } + return p.language.renderTemplate(segmentTemplate, p) } -func (n *php) init(props Properties, env Environment) { - n.language = language{ +func (p *php) init(props Properties, env Environment) { + p.language = language{ env: env, props: props, extensions: []string{"*.php", "composer.json", "composer.lock", ".php-version"}, @@ -24,6 +28,6 @@ func (n *php) init(props Properties, env Environment) { } } -func (n *php) enabled() bool { - return n.language.enabled() +func (p *php) enabled() bool { + return p.language.enabled() } diff --git a/src/segment_plastic.go b/src/segment_plastic.go index d1df3638..b2331a1b 100644 --- a/src/segment_plastic.go +++ b/src/segment_plastic.go @@ -50,34 +50,20 @@ func (p *plastic) enabled() bool { if p.shouldIgnoreRootRepository(wkdir.parentFolder) { return false } - - if wkdir.isDir { - p.plasticWorkspaceFolder = wkdir.parentFolder - return true + if !wkdir.isDir { + return false } - - return false -} - -func (p *plastic) string() string { + p.plasticWorkspaceFolder = wkdir.parentFolder displayStatus := p.props.getOneOfBool(FetchStatus, DisplayStatus, false) - p.setSelector() if displayStatus { p.setPlasticStatus() } - - // use template if available - segmentTemplate := p.props.getString(SegmentTemplate, "") - if len(segmentTemplate) > 0 { - return p.templateString(segmentTemplate) - } - - // default: only selector is returned - return p.Selector + return true } -func (p *plastic) templateString(segmentTemplate string) string { +func (p *plastic) string() string { + segmentTemplate := p.props.getString(SegmentTemplate, "{{ .Selector }}") template := &textTemplate{ Template: segmentTemplate, Context: p, diff --git a/src/segment_plastic_test.go b/src/segment_plastic_test.go index df51d4b4..b09e9d07 100644 --- a/src/segment_plastic_test.go +++ b/src/segment_plastic_test.go @@ -25,6 +25,7 @@ func TestPlasticEnabledInWorkspaceDirectory(t *testing.T) { env.On("hasCommand", "cm").Return(true) env.On("getRuntimeGOOS").Return("") env.On("isWsl").Return(false) + env.On("getFileContent", "/dir/.plastic//plastic.selector").Return("") fileInfo := &fileInfo{ path: "/dir/hello", parentFolder: "/dir", @@ -288,7 +289,7 @@ func TestPlasticTemplateString(t *testing.T) { Plastic *plastic }{ { - Case: "Only Selector name", + Case: "Default template", Expected: "/main", Template: "{{ .Selector }}", Plastic: &plastic{ @@ -325,12 +326,13 @@ func TestPlasticTemplateString(t *testing.T) { for _, tc := range cases { props := properties{ - FetchStatus: true, + FetchStatus: true, + SegmentTemplate: tc.Template, } tc.Plastic.props = props env := new(MockedEnvironment) env.onTemplate() tc.Plastic.env = env - assert.Equal(t, tc.Expected, tc.Plastic.templateString(tc.Template), tc.Case) + assert.Equal(t, tc.Expected, tc.Plastic.string(), tc.Case) } } diff --git a/src/segment_posh_git.go b/src/segment_posh_git.go index 5951b7b7..de8b6e82 100644 --- a/src/segment_posh_git.go +++ b/src/segment_posh_git.go @@ -3,9 +3,10 @@ package main import "strings" type poshgit struct { - props Properties - env Environment - gitStatus string + props Properties + env Environment + + Status string } const ( @@ -14,12 +15,22 @@ const ( func (p *poshgit) enabled() bool { status := p.env.getenv(poshGitEnv) - p.gitStatus = strings.TrimSpace(status) - return p.gitStatus != "" + p.Status = strings.TrimSpace(status) + return p.Status != "" } func (p *poshgit) string() string { - return p.gitStatus + segmentTemplate := p.props.getString(SegmentTemplate, "{{ .Status }}") + template := &textTemplate{ + Template: segmentTemplate, + Context: p, + Env: p.env, + } + text, err := template.render() + if err != nil { + return err.Error() + } + return text } func (p *poshgit) init(props Properties, env Environment) { diff --git a/src/segment_posh_git_test.go b/src/segment_posh_git_test.go index d8e3b3b7..bd91f7ac 100644 --- a/src/segment_posh_git_test.go +++ b/src/segment_posh_git_test.go @@ -20,9 +20,11 @@ func TestPoshGitSegment(t *testing.T) { for _, tc := range cases { env := new(MockedEnvironment) + env.onTemplate() env.On("getenv", poshGitEnv).Return(tc.PoshGitPrompt) p := &poshgit{ - env: env, + env: env, + props: &properties{}, } assert.Equal(t, tc.Enabled, p.enabled()) if tc.Enabled { diff --git a/src/segment_root.go b/src/segment_root.go index 258bccde..e4821594 100644 --- a/src/segment_root.go +++ b/src/segment_root.go @@ -5,17 +5,22 @@ type root struct { env Environment } -const ( - // RootIcon indicates the root user - RootIcon Property = "root_icon" -) - func (rt *root) enabled() bool { return rt.env.isRunningAsRoot() } func (rt *root) string() string { - return rt.props.getString(RootIcon, "\uF0E7") + segmentTemplate := rt.props.getString(SegmentTemplate, "\uF0E7") + template := &textTemplate{ + Template: segmentTemplate, + Context: rt, + Env: rt.env, + } + text, err := template.render() + if err != nil { + return err.Error() + } + return text } func (rt *root) init(props Properties, env Environment) { diff --git a/src/segment_ruby.go b/src/segment_ruby.go index 5b2eb009..9639ba7b 100644 --- a/src/segment_ruby.go +++ b/src/segment_ruby.go @@ -5,12 +5,16 @@ type ruby struct { } func (r *ruby) string() string { - version := r.language.string() - // asdf default non-set version - if version == "______" { - return "" + segmentTemplate := r.language.props.getString(SegmentTemplate, "") + if len(segmentTemplate) == 0 { + version := r.language.string() + // asdf default non-set version + if version == "______" { + return "" + } + return version } - return version + return r.language.renderTemplate(segmentTemplate, r) } func (r *ruby) init(props Properties, env Environment) { diff --git a/src/segment_rust.go b/src/segment_rust.go index 83192c69..21a43248 100644 --- a/src/segment_rust.go +++ b/src/segment_rust.go @@ -5,7 +5,11 @@ type rust struct { } func (r *rust) string() string { - return r.language.string() + segmentTemplate := r.language.props.getString(SegmentTemplate, "") + if len(segmentTemplate) == 0 { + return r.language.string() + } + return r.language.renderTemplate(segmentTemplate, r) } func (r *rust) init(props Properties, env Environment) { diff --git a/src/segment_session.go b/src/segment_session.go index f91b44a8..8be94f13 100644 --- a/src/segment_session.go +++ b/src/segment_session.go @@ -5,7 +5,7 @@ import "strings" type session struct { props Properties env Environment - text string + // text string userName string hostName string @@ -21,24 +21,24 @@ func (s *session) enabled() bool { if segmentTemplate == "" { return s.legacyEnabled() } + return true +} + +func (s *session) string() string { + segmentTemplate := s.props.getString(SegmentTemplate, "") + if segmentTemplate == "" { + return s.legacyString() + } template := &textTemplate{ Template: segmentTemplate, Context: s, Env: s.env, } - var err error - s.text, err = template.render() + text, err := template.render() if err != nil { - s.text = err.Error() + text = err.Error() } - return len(s.text) > 0 -} - -func (s *session) string() string { - if len(s.text) != 0 { - return s.text - } - return s.getFormattedText() + return text } func (s *session) init(props Properties, env Environment) { diff --git a/src/segment_session_test.go b/src/segment_session_test.go index acff040f..c3ef4a36 100644 --- a/src/segment_session_test.go +++ b/src/segment_session_test.go @@ -9,7 +9,6 @@ import ( func TestSessionSegmentTemplate(t *testing.T) { cases := []struct { Case string - ExpectedEnabled bool ExpectedString string UserName string DefaultUserName string @@ -19,56 +18,50 @@ func TestSessionSegmentTemplate(t *testing.T) { Template string }{ { - Case: "user and computer", - ExpectedString: "john@company-laptop", - ComputerName: "company-laptop", - UserName: "john", - Template: "{{.UserName}}@{{.HostName}}", - ExpectedEnabled: true, + Case: "user and computer", + ExpectedString: "john@company-laptop", + ComputerName: "company-laptop", + UserName: "john", + Template: "{{.UserName}}@{{.HostName}}", }, { - Case: "user only", - ExpectedString: "john", - UserName: "john", - Template: "{{.UserName}}", - ExpectedEnabled: true, + Case: "user only", + ExpectedString: "john", + UserName: "john", + Template: "{{.UserName}}", }, { - Case: "user with ssh", - ExpectedString: "john on remote", - UserName: "john", - SSHSession: true, - ComputerName: "remote", - Template: "{{.UserName}}{{if .SSHSession}} on {{.HostName}}{{end}}", - ExpectedEnabled: true, + Case: "user with ssh", + ExpectedString: "john on remote", + UserName: "john", + SSHSession: true, + ComputerName: "remote", + Template: "{{.UserName}}{{if .SSHSession}} on {{.HostName}}{{end}}", }, { - Case: "user without ssh", - ExpectedString: "john", - UserName: "john", - SSHSession: false, - ComputerName: "remote", - Template: "{{.UserName}}{{if .SSHSession}} on {{.HostName}}{{end}}", - ExpectedEnabled: true, + Case: "user without ssh", + ExpectedString: "john", + UserName: "john", + SSHSession: false, + ComputerName: "remote", + Template: "{{.UserName}}{{if .SSHSession}} on {{.HostName}}{{end}}", }, { - Case: "user with root and ssh", - ExpectedString: "super john on remote", - UserName: "john", - SSHSession: true, - ComputerName: "remote", - Root: true, - Template: "{{if .Root}}super {{end}}{{.UserName}}{{if .SSHSession}} on {{.HostName}}{{end}}", - ExpectedEnabled: true, + Case: "user with root and ssh", + ExpectedString: "super john on remote", + UserName: "john", + SSHSession: true, + ComputerName: "remote", + Root: true, + Template: "{{if .Root}}super {{end}}{{.UserName}}{{if .SSHSession}} on {{.HostName}}{{end}}", }, { - Case: "no template", - ExpectedString: "\uf817 john@remote", - UserName: "john", - SSHSession: true, - ComputerName: "remote", - Root: true, - ExpectedEnabled: true, + Case: "no template", + ExpectedString: "\uf817 john@remote", + UserName: "john", + SSHSession: true, + ComputerName: "remote", + Root: true, }, { Case: "default user not equal", @@ -79,7 +72,6 @@ func TestSessionSegmentTemplate(t *testing.T) { ComputerName: "remote", Root: true, Template: "{{if ne .Env.POSH_SESSION_DEFAULT_USER .UserName}}{{.UserName}}{{end}}", - ExpectedEnabled: true, }, { Case: "default user equal", @@ -90,7 +82,6 @@ func TestSessionSegmentTemplate(t *testing.T) { ComputerName: "remote", Root: true, Template: "{{if ne .Env.POSH_SESSION_DEFAULT_USER .UserName}}{{.UserName}}{{end}}", - ExpectedEnabled: false, }, } @@ -122,9 +113,7 @@ func TestSessionSegmentTemplate(t *testing.T) { SegmentTemplate: tc.Template, }, } - assert.Equal(t, tc.ExpectedEnabled, session.enabled(), tc.Case) - if tc.ExpectedEnabled { - assert.Equal(t, tc.ExpectedString, session.string(), tc.Case) - } + _ = session.enabled() + assert.Equal(t, tc.ExpectedString, session.string(), tc.Case) } } diff --git a/src/segment_shell.go b/src/segment_shell.go index 4b022289..1382e95c 100644 --- a/src/segment_shell.go +++ b/src/segment_shell.go @@ -5,6 +5,8 @@ import "strings" type shell struct { props Properties env Environment + + Name string } const ( @@ -13,19 +15,29 @@ const ( ) func (s *shell) enabled() bool { + mappedNames := s.props.getKeyValueMap(MappedShellNames, make(map[string]string)) + s.Name = s.env.getShellName() + for key, val := range mappedNames { + if strings.EqualFold(s.Name, key) { + s.Name = val + break + } + } return true } func (s *shell) string() string { - mappedNames := s.props.getKeyValueMap(MappedShellNames, make(map[string]string)) - shellName := s.env.getShellName() - for key, val := range mappedNames { - if strings.EqualFold(shellName, key) { - shellName = val - break - } + segmentTemplate := s.props.getString(SegmentTemplate, "{{.Name}}") + template := &textTemplate{ + Template: segmentTemplate, + Context: s, + Env: s.env, } - return shellName + text, err := template.render() + if err != nil { + return err.Error() + } + return text } func (s *shell) init(props Properties, env Environment) { diff --git a/src/segment_shell_test.go b/src/segment_shell_test.go index d8be4fb6..bbc0489c 100644 --- a/src/segment_shell_test.go +++ b/src/segment_shell_test.go @@ -10,10 +10,12 @@ func TestWriteCurrentShell(t *testing.T) { expected := "zsh" env := new(MockedEnvironment) env.On("getShellName").Return(expected, nil) + env.onTemplate() s := &shell{ env: env, props: properties{}, } + _ = s.enabled() assert.Equal(t, expected, s.string()) } @@ -29,12 +31,14 @@ func TestUseMappedShellNames(t *testing.T) { for _, tc := range cases { env := new(MockedEnvironment) env.On("getShellName").Return(tc.Expected, nil) + env.onTemplate() s := &shell{ env: env, props: properties{ MappedShellNames: map[string]string{"pwsh": "PS"}, }, } + _ = s.enabled() got := s.string() assert.Equal(t, tc.Expected, got) } diff --git a/src/segment_spotify.go b/src/segment_spotify.go index 1a257048..c89c2f87 100644 --- a/src/segment_spotify.go +++ b/src/segment_spotify.go @@ -1,15 +1,17 @@ package main -import ( - "fmt" -) - type spotify struct { - props Properties - env Environment - status string - artist string - track string + props Properties + env Environment + + MusicPlayer +} + +type MusicPlayer struct { + Status string + Artist string + Track string + Icon string } const ( @@ -19,24 +21,35 @@ const ( PausedIcon Property = "paused_icon" // StoppedIcon indicates a song is stopped StoppedIcon Property = "stopped_icon" - // TrackSeparator is put between the artist and the track - TrackSeparator Property = "track_separator" + + playing = "playing" + stopped = "stopped" + paused = "paused" ) func (s *spotify) string() string { - icon := "" - switch s.status { - case "stopped": - // in this case, no artist or track info - icon = s.props.getString(StoppedIcon, "\uF04D ") - return icon - case "paused": - icon = s.props.getString(PausedIcon, "\uF8E3 ") - case "playing": - icon = s.props.getString(PlayingIcon, "\uE602 ") + segmentTemplate := s.props.getString(SegmentTemplate, "{{.Icon}}{{ if ne .Status \"stopped\"}}{{.Artist}} - {{.Track}}{{ end }}") + template := &textTemplate{ + Template: segmentTemplate, + Context: s, + Env: s.env, + } + text, err := template.render() + if err != nil { + return err.Error() + } + return text +} +func (s *spotify) resolveIcon() { + switch s.Status { + case stopped: + // in this case, no artist or track info + s.Icon = s.props.getString(StoppedIcon, "\uF04D ") + case paused: + s.Icon = s.props.getString(PausedIcon, "\uF8E3 ") + case playing: + s.Icon = s.props.getString(PlayingIcon, "\uE602 ") } - separator := s.props.getString(TrackSeparator, " - ") - return fmt.Sprintf("%s%s%s%s", icon, s.artist, separator, s.track) } func (s *spotify) init(props Properties, env Environment) { diff --git a/src/segment_spotify_darwin.go b/src/segment_spotify_darwin.go index 1425c600..810263af 100644 --- a/src/segment_spotify_darwin.go +++ b/src/segment_spotify_darwin.go @@ -9,15 +9,16 @@ func (s *spotify) enabled() bool { if running == "false" || running == "" { return false } - s.status = s.runAppleScriptCommand("tell application \"Spotify\" to player state as string") + s.Status = s.runAppleScriptCommand("tell application \"Spotify\" to player state as string") if err != nil { return false } - if s.status == "stopped" { + if s.Status == stopped { return false } - s.artist = s.runAppleScriptCommand("tell application \"Spotify\" to artist of current track as string") - s.track = s.runAppleScriptCommand("tell application \"Spotify\" to name of current track as string") + s.Artist = s.runAppleScriptCommand("tell application \"Spotify\" to artist of current track as string") + s.Track = s.runAppleScriptCommand("tell application \"Spotify\" to name of current track as string") + s.resolveIcon() return true } diff --git a/src/segment_spotify_darwin_test.go b/src/segment_spotify_darwin_test.go index bc30d393..6fef1c10 100644 --- a/src/segment_spotify_darwin_test.go +++ b/src/segment_spotify_darwin_test.go @@ -22,6 +22,7 @@ func bootStrapSpotifyDarwinTest(args *spotifyArgs) *spotify { env.On("runCommand", "osascript", []string{"-e", "tell application \"Spotify\" to player state as string"}).Return(args.status, nil) env.On("runCommand", "osascript", []string{"-e", "tell application \"Spotify\" to artist of current track as string"}).Return(args.artist, nil) env.On("runCommand", "osascript", []string{"-e", "tell application \"Spotify\" to name of current track as string"}).Return(args.track, nil) + env.onTemplate() s := &spotify{ env: env, props: properties{}, diff --git a/src/segment_spotify_test.go b/src/segment_spotify_test.go index 5f6d3be8..bea5ce42 100644 --- a/src/segment_spotify_test.go +++ b/src/segment_spotify_test.go @@ -8,33 +8,34 @@ import ( func TestSpotifyStringPlayingSong(t *testing.T) { expected := "\ue602 Candlemass - Spellbreaker" + env := new(MockedEnvironment) + env.onTemplate() s := &spotify{ - artist: "Candlemass", - track: "Spellbreaker", - status: "playing", - props: properties{}, - } - assert.Equal(t, expected, s.string()) -} - -func TestSpotifyStringPausedSong(t *testing.T) { - expected := "\uF8E3 Candlemass - Spellbreaker" - s := &spotify{ - artist: "Candlemass", - track: "Spellbreaker", - status: "paused", - props: properties{}, + MusicPlayer: MusicPlayer{ + Artist: "Candlemass", + Track: "Spellbreaker", + Status: "playing", + Icon: "\ue602 ", + }, + props: properties{}, + env: env, } assert.Equal(t, expected, s.string()) } func TestSpotifyStringStoppedSong(t *testing.T) { expected := "\uf04d " + env := new(MockedEnvironment) + env.onTemplate() s := &spotify{ - artist: "Candlemass", - track: "Spellbreaker", - status: "stopped", - props: properties{}, + MusicPlayer: MusicPlayer{ + Artist: "Candlemass", + Track: "Spellbreaker", + Status: "stopped", + Icon: "\uf04d ", + }, + props: properties{}, + env: env, } assert.Equal(t, expected, s.string()) } diff --git a/src/segment_spotify_windows.go b/src/segment_spotify_windows.go index 54f9949a..79a31491 100644 --- a/src/segment_spotify_windows.go +++ b/src/segment_spotify_windows.go @@ -15,14 +15,15 @@ func (s *spotify) enabled() bool { } if !strings.Contains(spotifyWindowTitle, " - ") { - s.status = "stopped" + s.Status = stopped return false } infos := strings.Split(spotifyWindowTitle, " - ") - s.artist = infos[0] + s.Artist = infos[0] // remove first element and concat others(a song can contains also a " - ") - s.track = strings.Join(infos[1:], " - ") - s.status = "playing" + s.Track = strings.Join(infos[1:], " - ") + s.Status = playing + s.resolveIcon() return true } diff --git a/src/segment_spotify_windows_test.go b/src/segment_spotify_windows_test.go index 37153e3d..072d2180 100644 --- a/src/segment_spotify_windows_test.go +++ b/src/segment_spotify_windows_test.go @@ -17,6 +17,7 @@ type spotifyArgs struct { func bootStrapSpotifyWindowsTest(args *spotifyArgs) *spotify { env := new(MockedEnvironment) env.On("getWindowTitle", "spotify.exe").Return(args.title, args.runError) + env.onTemplate() s := &spotify{ env: env, props: properties{}, diff --git a/src/segment_spotify_wsl.go b/src/segment_spotify_wsl.go index 3e361a01..7e57e6a1 100644 --- a/src/segment_spotify_wsl.go +++ b/src/segment_spotify_wsl.go @@ -23,9 +23,10 @@ func (s *spotify) enabled() bool { title := record[len(record)-1] if strings.Contains(title, " - ") { infos := strings.Split(title, " - ") - s.artist = infos[0] - s.track = strings.Join(infos[1:], " - ") - s.status = "playing" + s.Artist = infos[0] + s.Track = strings.Join(infos[1:], " - ") + s.Status = playing + s.resolveIcon() return true } } diff --git a/src/segment_spotify_wsl_test.go b/src/segment_spotify_wsl_test.go index 2b9316bf..e951d398 100644 --- a/src/segment_spotify_wsl_test.go +++ b/src/segment_spotify_wsl_test.go @@ -54,6 +54,7 @@ func TestSpotifyWsl(t *testing.T) { env := new(MockedEnvironment) env.On("isWsl").Return(true) env.On("runCommand", "tasklist.exe", []string{"/V", "/FI", "Imagename eq Spotify.exe", "/FO", "CSV", "/NH"}).Return(tc.ExecOutput, nil) + env.onTemplate() s := &spotify{ env: env, props: properties{}, diff --git a/src/segment_text.go b/src/segment_text.go index 7a7c92c9..09cf5325 100644 --- a/src/segment_text.go +++ b/src/segment_text.go @@ -1,9 +1,10 @@ package main type text struct { - props Properties - env Environment - content string + props Properties + env Environment + + Text string } const ( @@ -19,14 +20,24 @@ func (t *text) enabled() bool { Env: t.env, } if text, err := template.render(); err == nil { - t.content = text - return len(t.content) > 0 + t.Text = text + return len(t.Text) > 0 } return false } func (t *text) string() string { - return t.content + segmentTemplate := t.props.getString(SegmentTemplate, "{{.Text}}") + template := &textTemplate{ + Template: segmentTemplate, + Context: t, + Env: t.env, + } + text, err := template.render() + if err != nil { + return err.Error() + } + return text } func (t *text) init(props Properties, env Environment) { diff --git a/src/segment_time.go b/src/segment_time.go index be6e46b6..9da95657 100644 --- a/src/segment_time.go +++ b/src/segment_time.go @@ -19,6 +19,11 @@ func (t *tempus) enabled() bool { if t.CurrentDate.IsZero() { t.CurrentDate = time.Now() } + + return true +} + +func (t *tempus) string() string { segmentTemplate := t.props.getString(SegmentTemplate, "") if segmentTemplate != "" { template := &textTemplate{ @@ -31,25 +36,16 @@ func (t *tempus) enabled() bool { if err != nil { t.templateText = err.Error() } - return len(t.templateText) > 0 + if len(t.templateText) > 0 { + return t.templateText + } } - return true -} - -func (t *tempus) string() string { - return t.getFormattedText() + // keep old behaviour if no template for now + timeFormatProperty := t.props.getString(TimeFormat, "15:04:05") + return t.CurrentDate.Format(timeFormatProperty) } func (t *tempus) init(props Properties, env Environment) { t.props = props t.env = env } - -func (t *tempus) getFormattedText() string { - if len(t.templateText) > 0 { - return t.templateText - } - // keep old behaviour if no template - timeFormatProperty := t.props.getString(TimeFormat, "15:04:05") - return t.CurrentDate.Format(timeFormatProperty) -} diff --git a/src/segment_ytm.go b/src/segment_ytm.go index 95a51cd6..58a3e793 100644 --- a/src/segment_ytm.go +++ b/src/segment_ytm.go @@ -2,15 +2,13 @@ package main import ( "encoding/json" - "fmt" ) type ytm struct { - props Properties - env Environment - status playStatus - artist string - track string + props Properties + env Environment + + MusicPlayer } const ( @@ -19,17 +17,17 @@ const ( ) func (y *ytm) string() string { - icon := "" - separator := y.props.getString(TrackSeparator, " - ") - switch y.status { - case paused: - icon = y.props.getString(PausedIcon, "\uF8E3 ") - case playing: - icon = y.props.getString(PlayingIcon, "\uE602 ") - case stopped: - return y.props.getString(StoppedIcon, "\uF04D ") + segmentTemplate := y.props.getString(SegmentTemplate, "{{.Icon}}{{ if ne .Status \"stopped\"}}{{.Artist}} - {{.Track}}{{ end }}") + template := &textTemplate{ + Template: segmentTemplate, + Context: y, + Env: y.env, } - return fmt.Sprintf("%s%s%s%s", icon, y.artist, separator, y.track) + text, err := template.render() + if err != nil { + return err.Error() + } + return text } func (y *ytm) enabled() bool { @@ -44,14 +42,6 @@ func (y *ytm) init(props Properties, env Environment) { y.env = env } -type playStatus int - -const ( - playing playStatus = iota - paused - stopped -) - type ytmdaStatusResponse struct { player `json:"player"` track `json:"track"` @@ -95,13 +85,16 @@ func (y *ytm) setStatus() error { if err != nil { return err } - y.status = playing + y.Status = playing + y.Icon = y.props.getString(PlayingIcon, "\uE602 ") if !q.player.HasSong { - y.status = stopped + y.Status = stopped + y.Icon = y.props.getString(StoppedIcon, "\uF04D ") } else if q.player.IsPaused { - y.status = paused + y.Status = paused + y.Icon = y.props.getString(PausedIcon, "\uF8E3 ") } - y.artist = q.track.Author - y.track = q.track.Title + y.Artist = q.track.Author + y.Track = q.track.Title return nil } diff --git a/src/segment_ytm_test.go b/src/segment_ytm_test.go index 0e77438b..45a30a7c 100644 --- a/src/segment_ytm_test.go +++ b/src/segment_ytm_test.go @@ -7,39 +7,6 @@ import ( "github.com/stretchr/testify/assert" ) -func TestYTMStringPlayingSong(t *testing.T) { - expected := "\ue602 Candlemass - Spellbreaker" - y := &ytm{ - artist: "Candlemass", - track: "Spellbreaker", - status: playing, - props: properties{}, - } - assert.Equal(t, expected, y.string()) -} - -func TestYTMStringPausedSong(t *testing.T) { - expected := "\uF8E3 Candlemass - Spellbreaker" - y := &ytm{ - artist: "Candlemass", - track: "Spellbreaker", - status: paused, - props: properties{}, - } - assert.Equal(t, expected, y.string()) -} - -func TestYTMStringStoppedSong(t *testing.T) { - expected := "\uf04d " - y := &ytm{ - artist: "Candlemass", - track: "Spellbreaker", - status: stopped, - props: properties{}, - } - assert.Equal(t, expected, y.string()) -} - func bootstrapYTMDATest(json string, err error) *ytm { url := "http://127.0.0.1:9863" env := new(MockedEnvironment) @@ -58,9 +25,9 @@ func TestYTMDAPlaying(t *testing.T) { ytm := bootstrapYTMDATest(json, nil) err := ytm.setStatus() assert.NoError(t, err) - assert.Equal(t, playing, ytm.status) - assert.Equal(t, "Candlemass", ytm.artist) - assert.Equal(t, "Spellbreaker", ytm.track) + assert.Equal(t, "playing", ytm.Status) + assert.Equal(t, "Candlemass", ytm.Artist) + assert.Equal(t, "Spellbreaker", ytm.Track) } func TestYTMDAPaused(t *testing.T) { @@ -68,9 +35,9 @@ func TestYTMDAPaused(t *testing.T) { ytm := bootstrapYTMDATest(json, nil) err := ytm.setStatus() assert.NoError(t, err) - assert.Equal(t, paused, ytm.status) - assert.Equal(t, "Candlemass", ytm.artist) - assert.Equal(t, "Spellbreaker", ytm.track) + assert.Equal(t, "paused", ytm.Status) + assert.Equal(t, "Candlemass", ytm.Artist) + assert.Equal(t, "Spellbreaker", ytm.Track) } func TestYTMDAStopped(t *testing.T) { @@ -78,9 +45,9 @@ func TestYTMDAStopped(t *testing.T) { ytm := bootstrapYTMDATest(json, nil) err := ytm.setStatus() assert.NoError(t, err) - assert.Equal(t, stopped, ytm.status) - assert.Equal(t, "", ytm.artist) - assert.Equal(t, "", ytm.track) + assert.Equal(t, "stopped", ytm.Status) + assert.Equal(t, "", ytm.Artist) + assert.Equal(t, "", ytm.Track) } func TestYTMDAError(t *testing.T) { diff --git a/src/template.go b/src/template.go index e74e02e6..0d41f423 100644 --- a/src/template.go +++ b/src/template.go @@ -39,6 +39,7 @@ type templateCache struct { Code int Env map[string]string OS string + WSL bool } func (c *Context) init(t *textTemplate) { @@ -85,7 +86,7 @@ func (t *textTemplate) cleanTemplate() { *knownVariables = append(*knownVariables, splitted[0]) return splitted[0], true } - knownVariables := []string{"Root", "PWD", "Folder", "Shell", "UserName", "HostName", "Env", "Data", "Code", "OS"} + knownVariables := []string{"Root", "PWD", "Folder", "Shell", "UserName", "HostName", "Env", "Data", "Code", "OS", "WSL"} matches := findAllNamedRegexMatch(`(?: |{|\()(?P(\.[a-zA-Z_][a-zA-Z0-9]*)+)`, t.Template) for _, match := range matches { if variable, OK := unknownVariable(match["var"], &knownVariables); OK { diff --git a/src/test/jandedobbeleer-palette.omp.json b/src/test/jandedobbeleer-palette.omp.json index 1da52e50..c17180fb 100644 --- a/src/test/jandedobbeleer-palette.omp.json +++ b/src/test/jandedobbeleer-palette.omp.json @@ -89,7 +89,7 @@ "background": "p:node", "properties": { "prefix": " \uF898 ", - "display_version": true + "fetch_version": true } }, { @@ -100,7 +100,7 @@ "background": "p:go", "properties": { "prefix": " \uE626 ", - "display_version": true + "fetch_version": true } }, { @@ -111,7 +111,7 @@ "background": "p:julia", "properties": { "prefix": " \uE624 ", - "display_version": true + "fetch_version": true } }, { @@ -135,7 +135,7 @@ "background": "p:ruby", "properties": { "prefix": " \uE791 ", - "display_version": true, + "fetch_version": true, "display_mode": "files" } }, @@ -147,7 +147,7 @@ "background": "p:azfunc", "properties": { "prefix": " \uf0e7", - "display_version": false, + "fetch_version": false, "display_mode": "files" } }, @@ -172,7 +172,7 @@ "foreground": "p:black", "background": "p:root", "properties": { - "root_icon": "" + "template": "" } }, { diff --git a/src/test/jandedobbeleer.omp.json b/src/test/jandedobbeleer.omp.json index 196894b8..d718fd06 100644 --- a/src/test/jandedobbeleer.omp.json +++ b/src/test/jandedobbeleer.omp.json @@ -58,7 +58,7 @@ "background": "#6CA35E", "properties": { "prefix": " \uF898 ", - "display_version": true + "fetch_version": true } }, { @@ -69,7 +69,7 @@ "background": "#8ED1F7", "properties": { "prefix": " \uE626 ", - "display_version": true + "fetch_version": true } }, { @@ -80,7 +80,7 @@ "background": "#4063D8", "properties": { "prefix": " \uE624 ", - "display_version": true + "fetch_version": true } }, { @@ -104,7 +104,7 @@ "background": "#AE1401", "properties": { "prefix": " \uE791 ", - "display_version": true, + "fetch_version": true, "display_mode": "files" } }, @@ -116,7 +116,7 @@ "background": "#FEAC19", "properties": { "prefix": " \uf0e7", - "display_version": false, + "fetch_version": false, "display_mode": "files" } }, @@ -141,7 +141,7 @@ "foreground": "#111111", "background": "#ffff66", "properties": { - "root_icon": "" + "template": "" } }, { diff --git a/themes/amro.omp.json b/themes/amro.omp.json index 0d5c1cb5..ac035112 100644 --- a/themes/amro.omp.json +++ b/themes/amro.omp.json @@ -50,7 +50,7 @@ "foreground": "#cd5e42", "properties": { "prefix": "", - "root_icon": "\ue3bf" + "template": "\ue3bf" } }, { diff --git a/themes/atomic.omp.json b/themes/atomic.omp.json index ff1c5a3a..7bb92806 100644 --- a/themes/atomic.omp.json +++ b/themes/atomic.omp.json @@ -26,7 +26,7 @@ "foreground": "#FFFB38", "background": "#ef5350", "properties": { - "root_icon": "\uf292", + "template": "\uf292", "prefix": "\uE0B0 " } }, diff --git a/themes/atomicBit.omp.json b/themes/atomicBit.omp.json index a3d6f7f7..38a5f20f 100644 --- a/themes/atomicBit.omp.json +++ b/themes/atomicBit.omp.json @@ -34,7 +34,7 @@ "properties": { "prefix": "<#ffffff>─(", "postfix": "<#ffffff>)", - "root_icon": "#" + "template": "#" } } ] diff --git a/themes/blue-owl.omp.json b/themes/blue-owl.omp.json index 7eaa8113..0659ead4 100644 --- a/themes/blue-owl.omp.json +++ b/themes/blue-owl.omp.json @@ -17,7 +17,7 @@ "background": "#a313a8", "properties": { "prefix": "", - "root_icon": "⚡" + "template": "⚡" } }, { diff --git a/themes/bubbles.omp.json b/themes/bubbles.omp.json index f6dc58a4..4e1e6582 100644 --- a/themes/bubbles.omp.json +++ b/themes/bubbles.omp.json @@ -56,7 +56,7 @@ "properties": { "prefix": "\uE235", "postfix": "", - "display_version": false + "fetch_version": false } }, { @@ -69,7 +69,7 @@ "properties": { "prefix": "\uFCD1", "postfix": "", - "display_version": false + "fetch_version": false } }, { @@ -82,7 +82,7 @@ "properties": { "prefix": "\uE718", "postfix": "", - "display_version": false + "fetch_version": false } }, { @@ -95,7 +95,7 @@ "properties": { "prefix": "\uE791", "postfix": "", - "display_version": false + "fetch_version": false } }, { @@ -108,7 +108,7 @@ "properties": { "prefix": "\uE738", "postfix": "", - "display_version": false + "fetch_version": false } }, { @@ -120,7 +120,7 @@ "background": "#29315A", "properties": { "prefix": "\uE624", - "display_version": false + "fetch_version": false } }, { diff --git a/themes/bubblesline.omp.json b/themes/bubblesline.omp.json index e1f54b10..0462d361 100644 --- a/themes/bubblesline.omp.json +++ b/themes/bubblesline.omp.json @@ -42,7 +42,7 @@ "properties": { "prefix": "\uE235", "postfix": "", - "display_version": false + "fetch_version": false } }, { @@ -55,7 +55,7 @@ "properties": { "prefix": "\uFCD1", "postfix": "", - "display_version": false + "fetch_version": false } }, { @@ -68,7 +68,7 @@ "properties": { "prefix": "\uE718", "postfix": "", - "display_version": false + "fetch_version": false } }, { @@ -81,7 +81,7 @@ "properties": { "prefix": "\uE791", "postfix": "", - "display_version": false + "fetch_version": false } }, { @@ -94,7 +94,7 @@ "properties": { "prefix": "\uE738", "postfix": "", - "display_version": false + "fetch_version": false } }, { @@ -107,7 +107,7 @@ "properties": { "prefix": "\uE624", "postfix": "", - "display_version": false + "fetch_version": false } }, { diff --git a/themes/clean-detailed.omp.json b/themes/clean-detailed.omp.json index 854f7980..8250c5c4 100644 --- a/themes/clean-detailed.omp.json +++ b/themes/clean-detailed.omp.json @@ -132,7 +132,7 @@ "type": "root", "style": "plain", "properties": { - "root_icon": "\uf292 " + "template": "\uf292 " } }, { @@ -165,4 +165,4 @@ ] } ] -} \ No newline at end of file +} diff --git a/themes/grandpa-style.omp.json b/themes/grandpa-style.omp.json index a6bedd0e..7d97c482 100644 --- a/themes/grandpa-style.omp.json +++ b/themes/grandpa-style.omp.json @@ -16,7 +16,7 @@ "foreground": "#dd1e1e", "background": "#000000", "properties": { - "root_icon": "⚡" + "template": "⚡" } }, { diff --git a/themes/hotstick.minimal.omp.json b/themes/hotstick.minimal.omp.json index 7b10ee95..d6284831 100644 --- a/themes/hotstick.minimal.omp.json +++ b/themes/hotstick.minimal.omp.json @@ -15,7 +15,7 @@ "style": "plain", "foreground": "yellow", "properties": { - "root_icon": "" + "template": "" } }, { diff --git a/themes/hunk.omp.json b/themes/hunk.omp.json index 0ab5832b..5b40b82c 100644 --- a/themes/hunk.omp.json +++ b/themes/hunk.omp.json @@ -49,7 +49,7 @@ "background": "#f78fb3", "properties": { "prefix": " \uE235 ", - "display_version": false + "fetch_version": false } }, { @@ -96,7 +96,7 @@ "background": "#86BBD8", "properties": { "postfix": "", - "root_icon": "⚡" + "template": "⚡" } }, { diff --git a/themes/iterm2.omp.json b/themes/iterm2.omp.json index 76a96d56..dacd4f93 100644 --- a/themes/iterm2.omp.json +++ b/themes/iterm2.omp.json @@ -132,7 +132,7 @@ "style": "plain", "foreground": "#FFD700", "properties": { - "root_icon": "⚡" + "template": "⚡" } }, { diff --git a/themes/jandedobbeleer.omp.json b/themes/jandedobbeleer.omp.json index c9f68663..5b559fa6 100644 --- a/themes/jandedobbeleer.omp.json +++ b/themes/jandedobbeleer.omp.json @@ -59,7 +59,7 @@ "background": "#6CA35E", "properties": { "prefix": " \uF898 ", - "display_version": true + "fetch_version": true } }, { @@ -70,7 +70,7 @@ "background": "#8ED1F7", "properties": { "prefix": " \uE626 ", - "display_version": true + "fetch_version": true } }, { @@ -81,7 +81,7 @@ "background": "#4063D8", "properties": { "prefix": " \uE624 ", - "display_version": true + "fetch_version": true } }, { @@ -105,7 +105,7 @@ "background": "#AE1401", "properties": { "prefix": " \uE791 ", - "display_version": true, + "fetch_version": true, "display_mode": "files" } }, @@ -117,7 +117,7 @@ "background": "#FEAC19", "properties": { "prefix": " \uf0e7", - "display_version": false, + "fetch_version": false, "display_mode": "files" } }, @@ -142,7 +142,7 @@ "foreground": "#111111", "background": "#ffff66", "properties": { - "root_icon": "" + "template": "" } }, { diff --git a/themes/jblab_2021.omp.json b/themes/jblab_2021.omp.json index 7a3031c9..085c95d0 100644 --- a/themes/jblab_2021.omp.json +++ b/themes/jblab_2021.omp.json @@ -16,8 +16,7 @@ "leading_diamond": "\uE0B6", "trailing_diamond": "\uE0B0", "properties": { - "wsl": "", - "wsl_separator": "" + "template": "{{ .Icon }}" }, "style": "diamond", "type": "os" diff --git a/themes/jonnychipz.omp.json b/themes/jonnychipz.omp.json index 81176e49..b5fa8257 100644 --- a/themes/jonnychipz.omp.json +++ b/themes/jonnychipz.omp.json @@ -85,10 +85,9 @@ "opensuse": "\uf314", "raspbian": "\uf315", "ubuntu": "\uf31c", - "wsl": "\ue712", - "wsl_separator": " on ", "windows": "\ue70f", - "postfix": "<#000000> \ue0b1" + "postfix": "<#000000> \ue0b1", + "template": "{{ if .WSL }}\ue712 on {{ end }}{{ .Icon }}" } }, @@ -98,7 +97,7 @@ "foreground": "#ffffff", "background": "#000000", "properties": { - "root_icon": "\uF0E7", + "template": "\uF0E7", "postfix": "<#ffffff> \ue0b1" } }, diff --git a/themes/mojada.omp.json b/themes/mojada.omp.json index d7d7134a..5957e1e0 100644 --- a/themes/mojada.omp.json +++ b/themes/mojada.omp.json @@ -43,7 +43,7 @@ "foreground": "#ffffff", "background": "#e06c75", "properties": { - "root_icon": "\uE799 ", + "template": "\uE799 ", "postfix": "\u2800" } }, diff --git a/themes/negligible.omp.json b/themes/negligible.omp.json index 5f9f8d38..070a9ece 100644 --- a/themes/negligible.omp.json +++ b/themes/negligible.omp.json @@ -44,7 +44,7 @@ "foreground": "red", "properties": { "prefix": "| ", - "root_icon": "root" + "template": "root" } }, { diff --git a/themes/night-owl.omp.json b/themes/night-owl.omp.json index 995e5078..8d62ce38 100644 --- a/themes/night-owl.omp.json +++ b/themes/night-owl.omp.json @@ -35,7 +35,7 @@ "foreground": "#ffeb95", "background": "#ef5350", "properties": { - "root_icon": "\uf292 " + "template": "\uf292 " } }, { diff --git a/themes/patriksvensson.omp.json b/themes/patriksvensson.omp.json index cb025b81..c82ec5a5 100644 --- a/themes/patriksvensson.omp.json +++ b/themes/patriksvensson.omp.json @@ -14,7 +14,7 @@ "foreground": "red", "properties": { "prefix": "", - "root_icon": "\uF0E7" + "template": "\uF0E7" } }, { diff --git a/themes/pixelrobots.omp.json b/themes/pixelrobots.omp.json index 0e79ba92..78c7a538 100644 --- a/themes/pixelrobots.omp.json +++ b/themes/pixelrobots.omp.json @@ -70,10 +70,9 @@ "opensuse": "\uf314", "raspbian": "\uf315", "ubuntu": "\uf31c", - "wsl": "\ue712", - "wsl_separator": " on ", "windows": "\ue70f", - "postfix": "<#ffea00> \ue0b1" + "postfix": "<#ffea00> \ue0b1", + "template": "{{ if .WSL }}\ue712 on {{ end }}{{ .Icon }}" } }, { @@ -92,7 +91,7 @@ "foreground": "#ffea00", "background": "#2f2f2f", "properties": { - "root_icon": "\uF0E7", + "template": "\uF0E7", "postfix": "<#ffea00> \ue0b1" } }, diff --git a/themes/powerlevel10k_modern.omp.json b/themes/powerlevel10k_modern.omp.json index 887886fd..4f0f2612 100644 --- a/themes/powerlevel10k_modern.omp.json +++ b/themes/powerlevel10k_modern.omp.json @@ -65,7 +65,7 @@ "foreground": "#ffffff", "background": "#7FD5EA", "leading_diamond": "\uE0B6", - "display_version": true, + "fetch_version": true, "properties": { "postfix": " <#000000>\uE0B6" } diff --git a/themes/powerlevel10k_rainbow.omp.json b/themes/powerlevel10k_rainbow.omp.json index 70537bdc..dfefab93 100644 --- a/themes/powerlevel10k_rainbow.omp.json +++ b/themes/powerlevel10k_rainbow.omp.json @@ -59,7 +59,7 @@ "background": "#689f63", "properties": { "postfix": " \uF898 ", - "display_version": true + "fetch_version": true } }, { @@ -71,7 +71,7 @@ "background": "#00acd7", "properties": { "postfix": " \uE627 ", - "display_version": true + "fetch_version": true } }, { @@ -83,7 +83,7 @@ "background": "#4063D8", "properties": { "postfix": " \uE624 ", - "display_version": true + "fetch_version": true } }, { @@ -109,7 +109,7 @@ "background": "#AE1401", "properties": { "postfix": " \uE791 ", - "display_version": true, + "fetch_version": true, "display_mode": "files" } }, @@ -122,7 +122,7 @@ "background": "#FEAC19", "properties": { "postfix": " \uf0e7", - "display_version": false, + "fetch_version": false, "display_mode": "files" } }, @@ -149,7 +149,7 @@ "foreground": "#111111", "background": "#ffff66", "properties": { - "root_icon": "\uF0AD" + "template": "\uF0AD" } }, { diff --git a/themes/rudolfs-dark.omp.json b/themes/rudolfs-dark.omp.json index 78772bb4..9c7716b8 100644 --- a/themes/rudolfs-dark.omp.json +++ b/themes/rudolfs-dark.omp.json @@ -17,8 +17,7 @@ "background": "#0A703E", "foreground": "#ffffff", "properties": { - "wsl": "", - "wsl_separator": "" + "template": "{{ .Icon }}" } }, { diff --git a/themes/rudolfs-light.omp.json b/themes/rudolfs-light.omp.json index 68fbeb2a..3114549e 100644 --- a/themes/rudolfs-light.omp.json +++ b/themes/rudolfs-light.omp.json @@ -17,8 +17,7 @@ "background": "#E0E0E0", "foreground": "#EF7D00", "properties": { - "wsl": "", - "wsl_separator": "" + "template": "{{ .Icon }}" } }, { diff --git a/themes/schema.json b/themes/schema.json index df8be900..22e70954 100644 --- a/themes/schema.json +++ b/themes/schema.json @@ -30,7 +30,7 @@ "description": "https://ohmyposh.dev/docs/config-overview#foreground-templates", "default": [], "items": { - "type": "string" + "$ref": "#/definitions/template" } }, "fetch_version": { @@ -65,7 +65,10 @@ "default": "" }, "template": { - "$ref": "#/definitions/template" + "type": "string", + "title": "Template text", + "description": "https://ohmyposh.dev/docs/config-text#templates", + "default": "" }, "block": { "type": "object", @@ -216,6 +219,9 @@ "description": "https://ohmyposh.dev/docs/config-overview#postfix", "default": " " }, + "template": { + "$ref": "#/definitions/template" + }, "include_folders": { "type": "array", "title": "If specified, segment will only render in these folders", @@ -302,16 +308,7 @@ }, "then": { "title": "Azure Segment", - "description": "https://ohmyposh.dev/docs/az", - "properties": { - "properties": { - "properties": { - "template": { - "$ref": "#/definitions/template" - } - } - } - } + "description": "https://ohmyposh.dev/docs/az" } }, { @@ -349,9 +346,6 @@ "title": "Charged Icon", "description": "Text/icon to display on the left when fully charged", "default": "" - }, - "template": { - "$ref": "#/definitions/template" } } } @@ -439,9 +433,6 @@ "title": "Always Enabled", "description": "Always show the status", "default": false - }, - "template": { - "$ref": "#/definitions/template" } } } @@ -460,9 +451,6 @@ "properties": { "properties": { "properties": { - "template": { - "$ref": "#/definitions/template" - }, "fetch_status": { "type": "boolean", "title": "Display Status", @@ -841,9 +829,6 @@ "properties": { "properties": { "properties": { - "template": { - "$ref": "#/definitions/template" - }, "display_error": { "type": "boolean", "title": "Display Error", @@ -873,9 +858,6 @@ "properties": { "properties": { "properties": { - "template": { - "$ref": "#/definitions/template" - }, "display_default": { "type": "boolean", "title": "Display Default User Profile", @@ -899,9 +881,6 @@ "properties": { "properties": { "properties": { - "template": { - "$ref": "#/definitions/template" - }, "fetch_version": { "$ref": "#/definitions/fetch_version" }, @@ -993,18 +972,6 @@ "description": "Icon/text to use for Windows", "default": "\uE62A" }, - "wsl": { - "type": "string", - "title": "WSL Icon", - "description": "Icon/text to use for WSL", - "default": "WSL" - }, - "wsl_separator": { - "type": "string", - "title": "WSL Separator", - "description": "Icon/text to use for separating WSL from Linux", - "default": " - " - }, "display_distro_name": { "type": "boolean", "title": "Display Distro Name", @@ -1203,10 +1170,7 @@ }, "enable_hyperlink": { "$ref": "#/definitions/enable_hyperlink" - }, - "template": { - "$ref": "#/definitions/template" - } + } } } } @@ -1238,9 +1202,6 @@ }, "enable_hyperlink": { "$ref": "#/definitions/enable_hyperlink" - }, - "template": { - "$ref": "#/definitions/template" } } } @@ -1255,19 +1216,7 @@ }, "then": { "title": "Root Segment", - "description": "https://ohmyposh.dev/docs/root", - "properties": { - "properties": { - "properties": { - "root_icon": { - "type": "string", - "title": "Root Icon", - "description": "The icon to display in case of root/elevated", - "default": "\uF0E7" - } - } - } - } + "description": "https://ohmyposh.dev/docs/root" } }, { @@ -1287,9 +1236,6 @@ "title": "SSH Icon", "description": "Text/icon to display first when in an active SSH session", "default": "\uF817" - }, - "template": { - "$ref": "#/definitions/template" } } } @@ -1411,9 +1357,6 @@ "title": "Time Format", "description": "Format to use, follows the golang standard: https://gobyexample.com/time-formatting-parsing", "default": "15:04:05" - }, - "template": { - "$ref": "#/definitions/template" } } } @@ -1512,9 +1455,6 @@ "title": "cache timeout", "description": "The number of minutes the response is cached. A value of 0 disables the cache.", "default": 10 - }, - "template": { - "$ref": "#/definitions/template" } } } @@ -1533,9 +1473,6 @@ "properties": { "properties": { "properties": { - "template": { - "$ref": "#/definitions/template" - }, "always_enabled": { "type": "boolean", "title": "Always Enabled", @@ -1596,9 +1533,6 @@ "title": "Precision", "description": "number of decimal places to show", "default": 0 - }, - "template": { - "$ref": "#/definitions/template" } } } @@ -1662,9 +1596,6 @@ "description": "The number of minutes the response is cached. A value of 0 disables the cache.", "default": 10 }, - "template": { - "$ref": "#/definitions/template" - }, "enable_hyperlink": { "$ref": "#/definitions/enable_hyperlink" } @@ -1722,9 +1653,6 @@ "title": "cache timeout", "description": "The number of minutes the response is cached. A value of 0 disables the cache.", "default": 10 - }, - "template": { - "$ref": "#/definitions/template" } } } @@ -1739,16 +1667,7 @@ }, "then": { "title": "WiFi Segment", - "description": "https://ohmyposh.dev/docs/wifi", - "properties": { - "properties": { - "properties": { - "template": { - "$ref": "#/definitions/template" - } - } - } - } + "description": "https://ohmyposh.dev/docs/wifi" } }, { @@ -1763,9 +1682,6 @@ "properties": { "properties": { "properties": { - "template": { - "$ref": "#/definitions/template" - }, "path": { "type": "string", "title": "Registry Path", @@ -1795,9 +1711,6 @@ "properties": { "properties": { "properties": { - "template": { - "$ref": "#/definitions/template" - }, "fetch_status": { "type": "boolean", "title": "Display Status", @@ -1851,9 +1764,6 @@ "properties": { "properties": { "properties": { - "template": { - "$ref": "#/definitions/template" - }, "user_id": { "type": "string", "title": "Brewfather UserID (required)", @@ -1996,9 +1906,6 @@ "title": "cache timeout", "description": "The number of minutes the response is cached. A value of 0 disables the cache.", "default": 10 - }, - "template": { - "$ref": "#/definitions/template" } } } diff --git a/themes/slim.omp.json b/themes/slim.omp.json index 5e99b59a..be54c0f4 100644 --- a/themes/slim.omp.json +++ b/themes/slim.omp.json @@ -30,10 +30,9 @@ "opensuse": "\uf314", "raspbian": "\uf315", "ubuntu": "\uf31c", - "wsl": "\ue712", - "wsl_separator": " on ", "windows": "\ue70f", - "postfix": "<#7a7a7a> \uE0b1" + "postfix": "<#7a7a7a> \uE0b1", + "template": "{{ if .WSL }}\ue712 on {{ end }}{{ .Icon }}" } }, { @@ -52,7 +51,7 @@ "foreground": "#ffff66", "background": "#2f2f2f", "properties": { - "root_icon": "\uF0E7", + "template": "\uF0E7", "postfix": "<#7a7a7a> \ue0b1" } }, diff --git a/themes/slimfat.omp.json b/themes/slimfat.omp.json index b5483fe3..93320b27 100644 --- a/themes/slimfat.omp.json +++ b/themes/slimfat.omp.json @@ -30,10 +30,9 @@ "opensuse": "\uf314", "raspbian": "\uf315", "ubuntu": "\uf31c", - "wsl": "\ue712", - "wsl_separator": " on ", "windows": "\ue70f", - "postfix": "<#7a7a7a> \ue0b1" + "postfix": "<#7a7a7a> \ue0b1", + "template": "{{ if .WSL }}\ue712 on {{ end }}{{ .Icon }}" } }, { @@ -52,7 +51,7 @@ "foreground": "#ffff66", "background": "#2f2f2f", "properties": { - "root_icon": "\uF0E7", + "template": "\uF0E7", "postfix": "<#7a7a7a> \ue0b1" } }, diff --git a/themes/smoothie.omp.json b/themes/smoothie.omp.json index b5b157d8..f8a4fc6f 100644 --- a/themes/smoothie.omp.json +++ b/themes/smoothie.omp.json @@ -46,7 +46,7 @@ "style": "plain", "foreground": "#98C379", "properties": { - "display_version": true, + "fetch_version": true, "prefix": "<#ffffff>\u25E6 \u2622" } } diff --git a/themes/sonicboom_dark.omp.json b/themes/sonicboom_dark.omp.json index be7274ba..99f3ef1a 100644 --- a/themes/sonicboom_dark.omp.json +++ b/themes/sonicboom_dark.omp.json @@ -1,135 +1,135 @@ -{ - "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json", - "final_space": true, - "osc99": true, - "blocks": [ - { - "type": "prompt", - "alignment": "left", - "segments": [ - { - "type": "root", - "style": "plain", - "foreground": "#dd1e1e", - "background": "#000000", - "properties": { - "root_icon": "⚡", - "postfix": "" - } - }, - { - "type": "os", - "style": "plain", - "foreground": "#ffffff", - "background": "#000000", - "properties": { - "alpine": "\uf300", - "arch": "\uf303", - "centos": "\uf304", - "debian": "\uf306", - "elementary": "\uf309", - "fedora": "\uf30a", - "gentoo": "\uf30d", - "linux": "\ue712", - "macos": "\ue711", - "manjaro": "\uf312", - "mint": "\uf30f", - "opensuse": "\uf314", - "raspbian": "\uf315", - "ubuntu": "\uf31c", - "wsl": "\ue712", - "windows": "\ue62a" - } - }, - { - "type": "path", - "style": "plain", - "foreground": "#43CCEA", - "background": "#272727", - "properties": { - "home_icon": "\uF7DB", - "folder_icon": "\ue5fe", - "folder_separator_icon": " \uE0BD ", - "style": "agnoster_short", - "enable_hyperlink": true - } - }, - { - "type": "git", - "style": "plain", - "foreground": "#00ff0d", - "background": "#272727", - "properties": { - "fetch_stash_count": true, - "fetch_status": true, - "template": "{{ .HEAD }}{{ if .Staging.Changed }}<#FF6F00> \uF046 {{ .Staging.String }}{{ end }}{{ if and (.Working.Changed) (.Staging.Changed) }} |{{ end }}{{ if .Working.Changed }} \uF044 {{ .Working.String }}{{ end }}{{ if gt .StashCount 0 }} \uF692 {{ .StashCount }}{{ end }}", - "prefix": "<#000000>\ue0b1 " - } - }, - { - "type": "executiontime", - "style": "diamond", - "trailing_diamond": "\uE0B0", - "foreground": "#ffffff", - "background": "#272727", - "properties": { - "threshold": 0, - "style": "dallas", - "prefix": "<#000000>\ue0b1 ", - "postfix": "s " - } - } - ] - }, - { - "type": "prompt", - "alignment": "right", - "segments": [ - { - "type": "session", - "style": "diamond", - "trailing_diamond": "", - "leading_diamond": "\uE0C5", - "foreground": "#43CCEA", - "background": "#272727", - "properties": { - "postfix": "", - "user_info_separator": " / " - } - }, - { - "type": "time", - "style": "diamond", - "trailing_diamond": "\uE0C5", - "leading_diamond": "", - "foreground": "#43CCEA", - "background": "#272727", - "properties": { - "time_format": "3:04:05 PM", - "prefix": "<#000000> \ue31e\uf0fb " - } - } - ] - }, - { - "type": "prompt", - "alignment": "left", - "newline": true, - "segments": [ - { - "type": "exit", - "style": "plain", - "foreground": "#00ff0d", - "foreground_templates": [ - "{{ if gt .Code 0 }}#ff0000{{ end }}" - ], - "properties": { - "template": "\ufb0c", - "prefix": "", - "always_enabled": true - } - } - ] - } - ] -} +{ + "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json", + "final_space": true, + "osc99": true, + "blocks": [ + { + "type": "prompt", + "alignment": "left", + "segments": [ + { + "type": "root", + "style": "plain", + "foreground": "#dd1e1e", + "background": "#000000", + "properties": { + "template": "⚡", + "postfix": "" + } + }, + { + "type": "os", + "style": "plain", + "foreground": "#ffffff", + "background": "#000000", + "properties": { + "alpine": "\uf300", + "arch": "\uf303", + "centos": "\uf304", + "debian": "\uf306", + "elementary": "\uf309", + "fedora": "\uf30a", + "gentoo": "\uf30d", + "linux": "\ue712", + "macos": "\ue711", + "manjaro": "\uf312", + "mint": "\uf30f", + "opensuse": "\uf314", + "raspbian": "\uf315", + "ubuntu": "\uf31c", + "wsl": "\ue712", + "windows": "\ue62a" + } + }, + { + "type": "path", + "style": "plain", + "foreground": "#43CCEA", + "background": "#272727", + "properties": { + "home_icon": "\uF7DB", + "folder_icon": "\ue5fe", + "folder_separator_icon": " \uE0BD ", + "style": "agnoster_short", + "enable_hyperlink": true + } + }, + { + "type": "git", + "style": "plain", + "foreground": "#00ff0d", + "background": "#272727", + "properties": { + "fetch_stash_count": true, + "fetch_status": true, + "template": "{{ .HEAD }}{{ if .Staging.Changed }}<#FF6F00> \uF046 {{ .Staging.String }}{{ end }}{{ if and (.Working.Changed) (.Staging.Changed) }} |{{ end }}{{ if .Working.Changed }} \uF044 {{ .Working.String }}{{ end }}{{ if gt .StashCount 0 }} \uF692 {{ .StashCount }}{{ end }}", + "prefix": "<#000000>\ue0b1 " + } + }, + { + "type": "executiontime", + "style": "diamond", + "trailing_diamond": "\uE0B0", + "foreground": "#ffffff", + "background": "#272727", + "properties": { + "threshold": 0, + "style": "dallas", + "prefix": "<#000000>\ue0b1 ", + "postfix": "s " + } + } + ] + }, + { + "type": "prompt", + "alignment": "right", + "segments": [ + { + "type": "session", + "style": "diamond", + "trailing_diamond": "", + "leading_diamond": "\uE0C5", + "foreground": "#43CCEA", + "background": "#272727", + "properties": { + "postfix": "", + "user_info_separator": " / " + } + }, + { + "type": "time", + "style": "diamond", + "trailing_diamond": "\uE0C5", + "leading_diamond": "", + "foreground": "#43CCEA", + "background": "#272727", + "properties": { + "time_format": "3:04:05 PM", + "prefix": "<#000000> \ue31e\uf0fb " + } + } + ] + }, + { + "type": "prompt", + "alignment": "left", + "newline": true, + "segments": [ + { + "type": "exit", + "style": "plain", + "foreground": "#00ff0d", + "foreground_templates": [ + "{{ if gt .Code 0 }}#ff0000{{ end }}" + ], + "properties": { + "template": "\ufb0c", + "prefix": "", + "always_enabled": true + } + } + ] + } + ] +} diff --git a/themes/sonicboom_light.omp.json b/themes/sonicboom_light.omp.json index 129cd6a0..434aed14 100644 --- a/themes/sonicboom_light.omp.json +++ b/themes/sonicboom_light.omp.json @@ -1,135 +1,135 @@ -{ - "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json", - "final_space": true, - "osc99": true, - "blocks": [ - { - "type": "prompt", - "alignment": "left", - "segments": [ - { - "type": "root", - "style": "plain", - "foreground": "#dd1e1e", - "background": "#000000", - "properties": { - "root_icon": "⚡", - "postfix": "" - } - }, - { - "type": "os", - "style": "plain", - "foreground": "#ffffff", - "background": "#000000", - "properties": { - "alpine": "\uf300", - "arch": "\uf303", - "centos": "\uf304", - "debian": "\uf306", - "elementary": "\uf309", - "fedora": "\uf30a", - "gentoo": "\uf30d", - "linux": "\ue712", - "macos": "\ue711", - "manjaro": "\uf312", - "mint": "\uf30f", - "opensuse": "\uf314", - "raspbian": "\uf315", - "ubuntu": "\uf31c", - "wsl": "\ue712", - "windows": "\ue62a" - } - }, - { - "type": "path", - "style": "plain", - "foreground": "#43CCEA", - "background": "#4d4d4d", - "properties": { - "home_icon": "\uF7DB", - "folder_icon": "\ue5fe", - "folder_separator_icon": " \uE0BD ", - "style": "agnoster_short", - "enable_hyperlink": true - } - }, - { - "type": "git", - "style": "plain", - "foreground": "#00ff0d", - "background": "#4d4d4d", - "properties": { - "fetch_stash_count": true, - "fetch_status": true, - "template": "{{ .HEAD }}{{ if .Staging.Changed }}<#FF6F00> \uF046 {{ .Staging.String }}{{ end }}{{ if and (.Working.Changed) (.Staging.Changed) }} |{{ end }}{{ if .Working.Changed }} \uF044 {{ .Working.String }}{{ end }}{{ if gt .StashCount 0 }} \uF692 {{ .StashCount }}{{ end }}", - "prefix": "<#000000>\ue0b1 " - } - }, - { - "type": "executiontime", - "style": "diamond", - "trailing_diamond": "\uE0B0", - "foreground": "#ffffff", - "background": "#4d4d4d", - "properties": { - "threshold": 0, - "style": "dallas", - "prefix": "<#000000>\ue0b1 ", - "postfix": "s " - } - } - ] - }, - { - "type": "prompt", - "alignment": "right", - "segments": [ - { - "type": "session", - "style": "diamond", - "trailing_diamond": "", - "leading_diamond": "\uE0C5", - "foreground": "#43CCEA", - "background": "#4d4d4d", - "properties": { - "postfix": "", - "user_info_separator": " / " - } - }, - { - "type": "time", - "style": "diamond", - "trailing_diamond": "\uE0C5", - "leading_diamond": "", - "foreground": "#43CCEA", - "background": "#4d4d4d", - "properties": { - "time_format": "3:04:05 PM", - "prefix": "<#000000> \ue31e\uf0fb " - } - } - ] - }, - { - "type": "prompt", - "alignment": "left", - "newline": true, - "segments": [ - { - "type": "exit", - "style": "plain", - "foreground": "#00ff0d", - "foreground_templates": [ - "{{ if gt .Code 0 }}#ff0000{{ end }}" - ], - "properties": { - "template": "\ufb0c", - "prefix": "", - "always_enabled": true - } - } - ] - } - ] -} +{ + "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json", + "final_space": true, + "osc99": true, + "blocks": [ + { + "type": "prompt", + "alignment": "left", + "segments": [ + { + "type": "root", + "style": "plain", + "foreground": "#dd1e1e", + "background": "#000000", + "properties": { + "template": "⚡", + "postfix": "" + } + }, + { + "type": "os", + "style": "plain", + "foreground": "#ffffff", + "background": "#000000", + "properties": { + "alpine": "\uf300", + "arch": "\uf303", + "centos": "\uf304", + "debian": "\uf306", + "elementary": "\uf309", + "fedora": "\uf30a", + "gentoo": "\uf30d", + "linux": "\ue712", + "macos": "\ue711", + "manjaro": "\uf312", + "mint": "\uf30f", + "opensuse": "\uf314", + "raspbian": "\uf315", + "ubuntu": "\uf31c", + "wsl": "\ue712", + "windows": "\ue62a" + } + }, + { + "type": "path", + "style": "plain", + "foreground": "#43CCEA", + "background": "#4d4d4d", + "properties": { + "home_icon": "\uF7DB", + "folder_icon": "\ue5fe", + "folder_separator_icon": " \uE0BD ", + "style": "agnoster_short", + "enable_hyperlink": true + } + }, + { + "type": "git", + "style": "plain", + "foreground": "#00ff0d", + "background": "#4d4d4d", + "properties": { + "fetch_stash_count": true, + "fetch_status": true, + "template": "{{ .HEAD }}{{ if .Staging.Changed }}<#FF6F00> \uF046 {{ .Staging.String }}{{ end }}{{ if and (.Working.Changed) (.Staging.Changed) }} |{{ end }}{{ if .Working.Changed }} \uF044 {{ .Working.String }}{{ end }}{{ if gt .StashCount 0 }} \uF692 {{ .StashCount }}{{ end }}", + "prefix": "<#000000>\ue0b1 " + } + }, + { + "type": "executiontime", + "style": "diamond", + "trailing_diamond": "\uE0B0", + "foreground": "#ffffff", + "background": "#4d4d4d", + "properties": { + "threshold": 0, + "style": "dallas", + "prefix": "<#000000>\ue0b1 ", + "postfix": "s " + } + } + ] + }, + { + "type": "prompt", + "alignment": "right", + "segments": [ + { + "type": "session", + "style": "diamond", + "trailing_diamond": "", + "leading_diamond": "\uE0C5", + "foreground": "#43CCEA", + "background": "#4d4d4d", + "properties": { + "postfix": "", + "user_info_separator": " / " + } + }, + { + "type": "time", + "style": "diamond", + "trailing_diamond": "\uE0C5", + "leading_diamond": "", + "foreground": "#43CCEA", + "background": "#4d4d4d", + "properties": { + "time_format": "3:04:05 PM", + "prefix": "<#000000> \ue31e\uf0fb " + } + } + ] + }, + { + "type": "prompt", + "alignment": "left", + "newline": true, + "segments": [ + { + "type": "exit", + "style": "plain", + "foreground": "#00ff0d", + "foreground_templates": [ + "{{ if gt .Code 0 }}#ff0000{{ end }}" + ], + "properties": { + "template": "\ufb0c", + "prefix": "", + "always_enabled": true + } + } + ] + } + ] +} diff --git a/themes/star.omp.json b/themes/star.omp.json index 92766b82..ab5190ca 100644 --- a/themes/star.omp.json +++ b/themes/star.omp.json @@ -10,7 +10,7 @@ "style": "plain", "foreground": "#E06C75", "properties": { - "root_icon": "root", + "template": "root", "prefix": "", "postfix": " <#ffffff>in " } @@ -39,7 +39,7 @@ "style": "plain", "foreground": "#98C379", "properties": { - "display_version": true, + "fetch_version": true, "prefix": "<#ffffff>via \uE781 " } }, diff --git a/themes/stelbent.minimal.omp.json b/themes/stelbent.minimal.omp.json index 9a58bc5f..0f62338b 100644 --- a/themes/stelbent.minimal.omp.json +++ b/themes/stelbent.minimal.omp.json @@ -22,7 +22,7 @@ "properties": { "prefix": " <#757575,>as ", "postfix": "", - "root_icon": "root" + "template": "root" } }, { diff --git a/themes/thecyberden.omp.json b/themes/thecyberden.omp.json index aeac7a1f..e2186f32 100644 --- a/themes/thecyberden.omp.json +++ b/themes/thecyberden.omp.json @@ -98,7 +98,7 @@ "foreground": "#ff0000", "properties": { "prefix": "", - "root_icon": "\uE00A" + "template": "\uE00A" } }, { diff --git a/themes/unicorn.omp.json b/themes/unicorn.omp.json index 610d6986..ebb73469 100644 --- a/themes/unicorn.omp.json +++ b/themes/unicorn.omp.json @@ -87,7 +87,7 @@ "style": "plain", "foreground": "#fff", "properties": { - "root_icon": "⚡" + "template": "⚡" } }, { diff --git a/themes/wopian.omp.json b/themes/wopian.omp.json index 3ac78b53..328d6056 100644 --- a/themes/wopian.omp.json +++ b/themes/wopian.omp.json @@ -12,8 +12,7 @@ "properties": { "prefix": "", "postfix": "", - "wsl": "", - "wsl_separator": "" + "template": "{{ .Icon }}" } }, { @@ -45,7 +44,7 @@ "style": "plain", "foreground": "#68a063", "properties": { - "display_version": true, + "fetch_version": true, "postfix": "", "display_mode": "files", "display_package_manager": true, @@ -58,7 +57,7 @@ "style": "plain", "foreground": "#4063D8", "properties": { - "display_version": true, + "fetch_version": true, "display_mode": "files", "postfix": "" } @@ -68,7 +67,7 @@ "style": "plain", "foreground": "#DE3F24", "properties": { - "display_version": true, + "fetch_version": true, "postfix": "", "display_mode": "files" } diff --git a/themes/xtoys.omp.json b/themes/xtoys.omp.json index bc1bffa9..fbb1133c 100644 --- a/themes/xtoys.omp.json +++ b/themes/xtoys.omp.json @@ -11,7 +11,7 @@ "foreground": "#CECE04", "properties": { "prefix": "", - "root_icon": "#" + "template": "#" } }, { diff --git a/themes/ys.omp.json b/themes/ys.omp.json index 5568cb57..b8539303 100644 --- a/themes/ys.omp.json +++ b/themes/ys.omp.json @@ -12,7 +12,7 @@ "properties": { "prefix": "(", "postfix": ")", - "display_version": false + "fetch_version": false } } ] @@ -36,7 +36,7 @@ "style": "plain", "foreground": "red", "properties": { - "root_icon": "%" + "template": "%" } }, {