From 6980cb55e7808654f1479b10875cc8f722a3817a Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Wed, 12 Oct 2022 14:59:37 +0200 Subject: [PATCH] feat: move default theme internally --- src/engine/config.go | 166 ++++++++++++++++++--- src/environment/shell.go | 2 +- themes/default.omp.json | 190 ------------------------ website/docs/installation/customize.mdx | 11 +- 4 files changed, 150 insertions(+), 219 deletions(-) delete mode 100644 themes/default.omp.json diff --git a/src/engine/config.go b/src/engine/config.go index e160e9ce..1fbeb5b6 100644 --- a/src/engine/config.go +++ b/src/engine/config.go @@ -8,6 +8,7 @@ import ( "oh-my-posh/color" "oh-my-posh/environment" "oh-my-posh/properties" + "oh-my-posh/segments" "os" "path/filepath" "strings" @@ -242,53 +243,174 @@ func defaultConfig() *Config { { Type: SESSION, Style: Diamond, - Background: "#c386f1", - Foreground: "#ffffff", - LeadingDiamond: "\uE0B6", - TrailingDiamond: "\uE0B0", + LeadingDiamond: "\ue0b6", + TrailingDiamond: "\ue0b0", + Background: "p:yellow", + Foreground: "p:black", + Template: " {{ if .SSHSession }}\uf817 {{ end }}{{ .UserName }} ", }, { Type: PATH, Style: Powerline, - PowerlineSymbol: "\uE0B0", - Background: "#ff479c", - Foreground: "#ffffff", + PowerlineSymbol: "\ue0b0", + Background: "p:orange", + Foreground: "p:white", Properties: properties.Map{ properties.Style: "folder", }, + Template: " \uf74a {{ path .Path .Location }} ", }, { - Type: SHELL, + Type: GIT, Style: Powerline, - PowerlineSymbol: "\uE0B0", - Background: "#0077c2", - Foreground: "#ffffff", + PowerlineSymbol: "\ue0b0", + Background: "p:green", + BackgroundTemplates: []string{ + "{{ if or (.Working.Changed) (.Staging.Changed) }}p:yellow{{ end }}", + "{{ if and (gt .Ahead 0) (gt .Behind 0) }}p:red{{ end }}", + "{{ if gt .Ahead 0 }}#49416D{{ end }}", + "{{ if gt .Behind 0 }}#7A306C{{ end }}", + }, + Foreground: "p:black", + ForegroundTemplates: []string{ + "{{ if or (.Working.Changed) (.Staging.Changed) }}p:black{{ end }}", + "{{ if and (gt .Ahead 0) (gt .Behind 0) }}p:white{{ end }}", + "{{ if gt .Ahead 0 }}p:white{{ end }}", + }, + Properties: properties.Map{ + segments.BranchMaxLength: 25, + segments.FetchStatus: true, + segments.FetchUpstreamIcon: true, + segments.GithubIcon: "\uf7a3", + }, + Template: " {{ if .UpstreamURL }}{{ url .UpstreamIcon .UpstreamURL }} {{ end }}{{ .HEAD }}{{if .BranchStatus }} {{ .BranchStatus }}{{ end }}{{ if .Working.Changed }} \uf044 {{ .Working.String }}{{ end }}{{ if .Staging.Changed }} \uf046 {{ .Staging.String }}{{ end }} ", //nolint:lll }, { - Type: TEXT, + Type: ROOT, Style: Powerline, - PowerlineSymbol: "\uE0B0", - Background: "#ffffff", - Foreground: "#111111", - Template: " no config ", + PowerlineSymbol: "\ue0b0", + Background: "p:yellow", + Foreground: "p:white", + Template: " \uf0e7 ", }, { Type: EXIT, Style: Diamond, - Background: "#2e9599", - Foreground: "#ffffff", - LeadingDiamond: "\uE0B0", - TrailingDiamond: "\uE0B4", + LeadingDiamond: "\ue0b0", + TrailingDiamond: "\ue0b4", + Background: "p:blue", BackgroundTemplates: []string{ - "{{ if gt .Code 0 }}#f1184c{{ end }}", + "{{ if gt .Code 0 }}p:red{{ end }}", }, - Template: " \uE23A ", + Foreground: "p:white", Properties: properties.Map{ properties.AlwaysEnabled: true, }, + Template: " {{ if gt .Code 0 }}\uf00d{{ else }}\uf00c{{ end }} ", }, }, }, + { + Type: RPrompt, + Segments: []*Segment{ + { + Type: NODE, + Style: Plain, + Background: "transparent", + Foreground: "p:green", + Template: "\uf898 ", + Properties: properties.Map{ + segments.HomeEnabled: false, + segments.FetchPackageManager: false, + segments.DisplayMode: "files", + }, + }, + { + Type: GOLANG, + Style: Plain, + Background: "transparent", + Foreground: "p:blue", + Template: "\ufcd1 ", + Properties: properties.Map{ + properties.FetchVersion: false, + }, + }, + { + Type: PYTHON, + Style: Plain, + Background: "transparent", + Foreground: "p:yellow", + Template: "\ue235 ", + Properties: properties.Map{ + properties.FetchVersion: false, + segments.DisplayMode: "files", + segments.FetchVirtualEnv: false, + }, + }, + { + Type: SHELL, + Style: Plain, + Background: "transparent", + Foreground: "p:white", + Template: "in {{ .Name }} ", + }, + { + Type: TIME, + Style: Plain, + Background: "transparent", + Foreground: "p:white", + Template: "at {{ .CurrentDate | date \"15:04:05\" }}", + }, + }, + }, + }, + ConsoleTitleTemplate: "{{ .Shell }} in {{ .Folder }}", + Palette: color.Palette{ + "black": "#262B44", + "blue": "#4B95E9", + "green": "#59C9A5", + "orange": "#F07623", + "red": "#D81E5B", + "white": "#E0DEF4", + "yellow": "#F3AE35", + }, + SecondaryPrompt: &Segment{ + Background: "transparent", + Foreground: "p:black", + Template: "\ue0b6<,p:yellow> > \ue0b0 ", + }, + TransientPrompt: &Segment{ + Background: "transparent", + Foreground: "p:black", + Template: "\ue0b6<,p:yellow> {{ .Folder }} \ue0b0 ", + }, + Tooltips: []*Segment{ + { + Type: AWS, + Style: Diamond, + LeadingDiamond: "\ue0b0", + TrailingDiamond: "\ue0b4", + Background: "p:orange", + Foreground: "p:white", + Template: " \ue7ad {{ .Profile }}{{ if .Region }}@{{ .Region }}{{ end }} ", + Properties: properties.Map{ + properties.DisplayDefault: true, + }, + Tips: []string{"aws"}, + }, + { + Type: AZ, + Style: Diamond, + LeadingDiamond: "\ue0b0", + TrailingDiamond: "\ue0b4", + Background: "p:blue", + Foreground: "p:white", + Template: " \ufd03 {{ .Name }} ", + Properties: properties.Map{ + properties.DisplayDefault: true, + }, + Tips: []string{"az"}, + }, }, } return cfg diff --git a/src/environment/shell.go b/src/environment/shell.go index d6f51f9e..a51831e1 100644 --- a/src/environment/shell.go +++ b/src/environment/shell.go @@ -254,7 +254,7 @@ func (env *ShellEnvironment) resolveConfigPath() { env.CmdFlags.Config = env.Getenv("POSH_THEME") } if len(env.CmdFlags.Config) == 0 { - env.CmdFlags.Config = fmt.Sprintf("https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/v%s/themes/default.omp.json", env.Version) + return } if strings.HasPrefix(env.CmdFlags.Config, "https://") { if err := env.downloadConfig(env.CmdFlags.Config); err != nil { diff --git a/themes/default.omp.json b/themes/default.omp.json deleted file mode 100644 index a9f03ac0..00000000 --- a/themes/default.omp.json +++ /dev/null @@ -1,190 +0,0 @@ -{ - "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json", - "blocks": [ - { - "alignment": "left", - "segments": [ - { - "background": "p:yellow", - "foreground": "p:black", - "leading_diamond": "\ue0b6", - "properties": { - "display_host": false - }, - "style": "diamond", - "template": " {{ if .SSHSession }}\uf817 {{ end }}{{ .UserName }} ", - "trailing_diamond": "\ue0b0", - "type": "session" - }, - { - "background": "p:orange", - "foreground": "p:white", - "powerline_symbol": "\ue0b0", - "properties": { - "home_icon": "~", - "style": "folder" - }, - "style": "powerline", - "template": " \uf74a {{ path .Path .Location }} ", - "type": "path" - }, - { - "background": "p:green", - "background_templates": [ - "{{ if or (.Working.Changed) (.Staging.Changed) }}p:yellow{{ end }}", - "{{ if and (gt .Ahead 0) (gt .Behind 0) }}p:red{{ end }}", - "{{ if gt .Ahead 0 }}#49416D{{ end }}", - "{{ if gt .Behind 0 }}#7A306C{{ end }}" - ], - "foreground": "p:black", - "foreground_templates": [ - "{{ if or (.Working.Changed) (.Staging.Changed) }}p:black{{ end }}", - "{{ if and (gt .Ahead 0) (gt .Behind 0) }}p:white{{ end }}", - "{{ if gt .Ahead 0 }}p:white{{ end }}" - ], - "powerline_symbol": "\ue0b0", - "properties": { - "branch_max_length": 25, - "fetch_status": true, - "fetch_upstream_icon": true, - "github_icon": "\uf7a3" - }, - "style": "powerline", - "template": " {{ if .UpstreamURL }}{{ url .UpstreamIcon .UpstreamURL }} {{ end }}{{ .HEAD }}{{if .BranchStatus }} {{ .BranchStatus }}{{ end }}{{ if .Working.Changed }} \uf044 {{ .Working.String }}{{ end }}{{ if .Staging.Changed }} \uf046 {{ .Staging.String }}{{ end }} ", - "type": "git" - }, - { - "background": "p:yellow", - "foreground": "p:white", - "powerline_symbol": "\ue0b0", - "properties": { - "root_icon": "\uf0ad" - }, - "style": "powerline", - "template": " \uf0e7 ", - "type": "root" - }, - { - "background": "p:blue", - "background_templates": [ - "{{ if gt .Code 0 }}p:red{{ end }}" - ], - "foreground": "p:white", - "leading_diamond": "\ue0b0", - "properties": { - "always_enabled": true - }, - "style": "diamond", - "template": " {{ if gt .Code 0 }}\uf00d{{ else }}\uf00c{{ end }} ", - "trailing_diamond": "\ue0b4", - "type": "exit" - } - ], - "type": "prompt" - }, - { - "segments": [ - { - "background": "transparent", - "foreground": "p:green", - "properties": { - "display_mode": "files", - "fetch_package_manager": false, - "home_enabled": false - }, - "style": "plain", - "template": "\uf898 ", - "type": "node" - }, - { - "background": "transparent", - "foreground": "p:blue", - "properties": { - "fetch_version": false - }, - "style": "powerline", - "template": "\ufcd1 ", - "type": "go" - }, - { - "background": "transparent", - "foreground": "p:yellow", - "properties": { - "display_mode": "files", - "fetch_version": true, - "fetch_virtual_env": false - }, - "style": "plain", - "template": "\ue235 ", - "type": "python" - }, - { - "background": "transparent", - "foreground": "p:white", - "style": "plain", - "template": "in {{ .Name }} ", - "type": "shell" - }, - { - "background": "transparent", - "foreground": "p:white", - "style": "plain", - "template": "at {{ .CurrentDate | date \"15:04:05\" }}", - "type": "time" - } - ], - "type": "rprompt" - } - ], - "console_title_template": "{{ .Shell }} in {{ .Folder }}", - "final_space": true, - "palette": { - "black": "#262B44", - "blue": "#4B95E9", - "green": "#59C9A5", - "orange": "#F07623", - "red": "#D81E5B", - "white": "#E0DEF4", - "yellow": "#F3AE35" - }, - "secondary_prompt": { - "background": "transparent", - "foreground": "p:black", - "template": "\ue0b6<,p:yellow> > \ue0b0 " - }, - "tooltips": [ - { - "background": "p:orange", - "foreground": "p:white", - "leading_diamond": "\ue0b6", - "properties": { - "display_default": true - }, - "style": "diamond", - "template": " \ue7ad {{ .Profile }}{{ if .Region }}@{{ .Region }}{{ end }} ", - "tips": [ - "aws" - ], - "trailing_diamond": "\ue0b4", - "type": "aws" - }, - { - "background": "p:blue", - "foreground": "p:white", - "leading_diamond": "\ue0b6", - "style": "diamond", - "template": " \ufd03 {{ .Name }} ", - "tips": [ - "az" - ], - "trailing_diamond": "\ue0b4", - "type": "az" - } - ], - "transient_prompt": { - "background": "transparent", - "foreground": "p:black", - "template": "\ue0b6<,p:yellow> {{ .Folder }} \ue0b0 " - }, - "version": 2 -} diff --git a/website/docs/installation/customize.mdx b/website/docs/installation/customize.mdx index 69d1d877..6fd4ebab 100644 --- a/website/docs/installation/customize.mdx +++ b/website/docs/installation/customize.mdx @@ -7,12 +7,12 @@ sidebar_label: 💅🏼 Customize import Tabs from "@theme/Tabs"; import TabItem from "@theme/TabItem" -The standard initialization sets Oh My Posh' [default theme][default-theme]. This configuration is downloaded -and kept up-to-date with Oh My Posh' version every time the shell starts. +The standard initialization sets Oh My Posh' default theme. This configuration is embedded +and thus kept up-to-date with Oh My Posh. -To set a new config/theme you need -to change the `--config` option of the `oh-my-posh init ` line in your `profile` or `.rc` script -(see [prompt][prompt]) and point it to the location of a predefined [theme][themes] or custom configuration. +To set a new config/theme you need to change the `--config` option of the `oh-my-posh init ` +line in your `profile` or `.rc` script (see [prompt][prompt]) and point it to the location of a +predefined [theme][themes] or custom configuration. There are two possible values the `--config` flag can handle: @@ -241,7 +241,6 @@ segments section covers how to configure each available segment. [themes]: themes.md [configuration]: configuration/overview.mdx [prompt]: prompt.mdx -[default-theme]: https://github.com/JanDeDobbeleer/oh-my-posh/blob/main/themes/default.omp.json [jandedobbeleer]: /docs/themes#jandedobbeleer [json-schema]: https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json [homebrew-problem]: https://github.com/JanDeDobbeleer/oh-my-posh/discussions/2644