diff --git a/docs/docs/config-title.md b/docs/docs/config-title.md index a60624ea..5113db3f 100644 --- a/docs/docs/config-title.md +++ b/docs/docs/config-title.md @@ -14,23 +14,8 @@ sidebar_label: Console title } ``` -To manipulate the console title, you can make use of the following properties: - -- console_title: `boolean` - when true sets the current location as the console title -- console_title_style: `string` - the title to set in the console - defaults to `folder` -- console_title_template: `string` - the template to use when `"console_title_style" = "template"` - -### Console Title Style - -- `folder`: show the current folder name -- `path`: show the current path -- `template`: show a custom template - ### Console Title Template -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. - The following examples illustrate possible contents for `console_title_template`, provided the current working directory is `/usr/home/omp` and the shell is `zsh`. diff --git a/src/cli/config_export_image.go b/src/cli/config_export_image.go index 749ffe8b..b63bc6ea 100644 --- a/src/cli/config_export_image.go +++ b/src/cli/config_export_image.go @@ -61,7 +61,6 @@ You can tweak the output by using additional flags: Env: env, Ansi: ansi, Template: cfg.ConsoleTitleTemplate, - Style: cfg.ConsoleTitleStyle, } eng := &engine.Engine{ Config: cfg, diff --git a/src/cli/prompt_print.go b/src/cli/prompt_print.go index ef5d24b7..ba235209 100644 --- a/src/cli/prompt_print.go +++ b/src/cli/prompt_print.go @@ -62,7 +62,11 @@ var printCmd = &cobra.Command{ defer env.Close() cfg := engine.LoadConfig(env) ansi := &color.Ansi{} - ansi.Init(env.Shell()) + shell := env.Shell() + if debug { + shell = "shell" + } + ansi.Init(shell) var writer color.Writer if plain { writer = &color.PlainWriter{} @@ -78,7 +82,6 @@ var printCmd = &cobra.Command{ Env: env, Ansi: ansi, Template: cfg.ConsoleTitleTemplate, - Style: cfg.ConsoleTitleStyle, } eng := &engine.Engine{ Config: cfg, diff --git a/src/console/title.go b/src/console/title.go index ffcf21ea..d9eced80 100644 --- a/src/console/title.go +++ b/src/console/title.go @@ -4,40 +4,16 @@ import ( "oh-my-posh/color" "oh-my-posh/environment" "oh-my-posh/template" - "strings" ) type Title struct { Env environment.Environment Ansi *color.Ansi - Style Style Template string } -// Style defines how to show the title in the console window -type Style string - -const ( - // FolderName show the current folder name - FolderName Style = "folder" - // FullPath show the current path - FullPath Style = "path" - // Template allows a more powerful custom string - Template Style = "template" -) - func (t *Title) GetTitle() string { - var title string - switch t.Style { - case FullPath: - title = t.getPwd() - case Template: - title = t.getTitleTemplateText() - case FolderName: - fallthrough - default: - title = environment.Base(t.Env, t.getPwd()) - } + title := t.getTitleTemplateText() title = t.Ansi.EscapeText(title) return t.Ansi.Title(title) } @@ -52,9 +28,3 @@ func (t *Title) getTitleTemplateText() string { } return "" } - -func (t *Title) getPwd() string { - pwd := t.Env.Pwd() - pwd = strings.Replace(pwd, t.Env.Home(), "~", 1) - return pwd -} diff --git a/src/console/title_test.go b/src/console/title_test.go index f6af0f0b..b27c305f 100644 --- a/src/console/title_test.go +++ b/src/console/title_test.go @@ -11,7 +11,6 @@ import ( func TestGetTitle(t *testing.T) { cases := []struct { - Style Style Template string Root bool User string @@ -20,10 +19,7 @@ func TestGetTitle(t *testing.T) { ShellName string Expected string }{ - {Style: FolderName, Cwd: "/usr/home", PathSeparator: "/", ShellName: "default", Expected: "\x1b]0;~\a"}, - {Style: FullPath, Cwd: "/usr/home/jan", PathSeparator: "/", ShellName: "default", Expected: "\x1b]0;~/jan\a"}, { - Style: Template, Template: "{{.Env.USERDOMAIN}} :: {{.PWD}}{{if .Root}} :: Admin{{end}} :: {{.Shell}}", Cwd: "C:\\vagrant", PathSeparator: "\\", @@ -32,7 +28,6 @@ func TestGetTitle(t *testing.T) { Expected: "\x1b]0;MyCompany :: C:\\vagrant :: Admin :: PowerShell\a", }, { - Style: Template, Template: "{{.Folder}}{{if .Root}} :: Admin{{end}} :: {{.Shell}}", Cwd: "C:\\vagrant", PathSeparator: "\\", @@ -40,7 +35,6 @@ func TestGetTitle(t *testing.T) { Expected: "\x1b]0;vagrant :: PowerShell\a", }, { - Style: Template, Template: "{{.UserName}}@{{.HostName}}{{if .Root}} :: Admin{{end}} :: {{.Shell}}", Root: true, User: "MyUser", @@ -71,7 +65,6 @@ func TestGetTitle(t *testing.T) { ct := &Title{ Env: env, Ansi: ansi, - Style: tc.Style, Template: tc.Template, } got := ct.GetTitle() @@ -81,7 +74,6 @@ func TestGetTitle(t *testing.T) { func TestGetConsoleTitleIfGethostnameReturnsError(t *testing.T) { cases := []struct { - Style Style Template string Root bool User string @@ -91,7 +83,6 @@ func TestGetConsoleTitleIfGethostnameReturnsError(t *testing.T) { Expected string }{ { - Style: Template, Template: "Not using Host only {{.UserName}} and {{.Shell}}", User: "MyUser", PathSeparator: "\\", @@ -99,7 +90,6 @@ func TestGetConsoleTitleIfGethostnameReturnsError(t *testing.T) { Expected: "\x1b]0;Not using Host only MyUser and PowerShell\a", }, { - Style: Template, Template: "{{.UserName}}@{{.HostName}} :: {{.Shell}}", User: "MyUser", PathSeparator: "\\", @@ -126,7 +116,6 @@ func TestGetConsoleTitleIfGethostnameReturnsError(t *testing.T) { ct := &Title{ Env: env, Ansi: ansi, - Style: tc.Style, Template: tc.Template, } got := ct.GetTitle() diff --git a/src/engine/config.go b/src/engine/config.go index 2a5505f2..62bb25d4 100644 --- a/src/engine/config.go +++ b/src/engine/config.go @@ -6,7 +6,6 @@ import ( "fmt" "io" "oh-my-posh/color" - "oh-my-posh/console" "oh-my-posh/environment" "oh-my-posh/properties" "os" @@ -33,8 +32,6 @@ type Config struct { Version int `json:"version"` FinalSpace bool `json:"final_space,omitempty"` OSC99 bool `json:"osc99,omitempty"` - ConsoleTitle bool `json:"console_title,omitempty"` - ConsoleTitleStyle console.Style `json:"console_title_style,omitempty"` ConsoleTitleTemplate string `json:"console_title_template,omitempty"` TerminalBackground string `json:"terminal_background,omitempty"` Blocks []*Block `json:"blocks,omitempty"` diff --git a/src/engine/engine.go b/src/engine/engine.go index 307d0300..f09affa1 100644 --- a/src/engine/engine.go +++ b/src/engine/engine.go @@ -60,7 +60,7 @@ func (e *Engine) PrintPrimary() string { for _, block := range e.Config.Blocks { e.renderBlock(block) } - if e.Config.ConsoleTitle { + if len(e.Config.ConsoleTitleTemplate) > 0 { e.writeANSI(e.ConsoleTitle.GetTitle()) } e.writeANSI(e.Ansi.ColorReset()) @@ -167,13 +167,15 @@ func (e *Engine) PrintDebug(version string) string { e.write("\n\x1b[1mSegments:\x1b[0m\n\n") // console title timing start := time.Now() - consoleTitle := e.ConsoleTitle.GetTitle() + title := e.ConsoleTitle.GetTitle() + title = strings.TrimPrefix(title, "\x1b]0;") + title = strings.TrimSuffix(title, "\a") duration := time.Since(start) segmentTiming := &SegmentTiming{ name: "ConsoleTitle", nameLength: 12, - active: e.Config.ConsoleTitle, - text: consoleTitle, + active: len(e.Config.ConsoleTitleTemplate) > 0, + text: title, duration: duration, } segmentTimings = append(segmentTimings, segmentTiming) diff --git a/src/engine/engine_test.go b/src/engine/engine_test.go index 6f4b1858..91118c9e 100644 --- a/src/engine/engine_test.go +++ b/src/engine/engine_test.go @@ -67,7 +67,6 @@ func engineRender() { consoleTitle := &console.Title{ Env: env, Ansi: ansi, - Style: cfg.ConsoleTitleStyle, Template: cfg.ConsoleTitleTemplate, } engine := &Engine{ diff --git a/src/test/jandedobbeleer-palette.omp.json b/src/test/jandedobbeleer-palette.omp.json index 5e852b74..9033ff70 100644 --- a/src/test/jandedobbeleer-palette.omp.json +++ b/src/test/jandedobbeleer-palette.omp.json @@ -229,8 +229,6 @@ "type": "rprompt" } ], - "console_title": true, - "console_title_style": "template", "console_title_template": "{{ .Shell }} in {{ .Folder }}", "final_space": true, "palette": { diff --git a/src/test/jandedobbeleer.omp.json b/src/test/jandedobbeleer.omp.json index 3b84c0b7..7da9b61d 100644 --- a/src/test/jandedobbeleer.omp.json +++ b/src/test/jandedobbeleer.omp.json @@ -229,8 +229,6 @@ "type": "rprompt" } ], - "console_title": true, - "console_title_style": "template", "console_title_template": "{{ .Shell }} in {{ .Folder }}", "final_space": true, "version": 1 diff --git a/themes/blue-owl.omp.json b/themes/blue-owl.omp.json index 4ce50f23..a36a7572 100644 --- a/themes/blue-owl.omp.json +++ b/themes/blue-owl.omp.json @@ -127,8 +127,6 @@ "type": "prompt" } ], - "console_title": true, - "console_title_style": "template", "console_title_template": "{{if .Root}} \u26a1 {{end}}{{.Folder | replace \"~\" \"🏚\" }} @ {{.HostName}}", "osc99": true, "version": 1 diff --git a/themes/capr4n.omp.json b/themes/capr4n.omp.json index 47c90979..123d64f3 100644 --- a/themes/capr4n.omp.json +++ b/themes/capr4n.omp.json @@ -42,7 +42,7 @@ }, { "background": "#C678DD", - "foreground": "ffffff", + "foreground": "#ffffff", "powerline_symbol": "\ue0b0", "properties": { "folder_icon": "\uf115", @@ -68,8 +68,6 @@ "type": "prompt" } ], - "console_title": true, - "console_title_style": "template", "console_title_template": "{{if .Root}} \u26a1 {{end}}{{.UserName}} \u2794 📁{{.Folder}}", "final_space": true, "version": 1 diff --git a/themes/clean-detailed.omp.json b/themes/clean-detailed.omp.json index 74b63991..e41e3af1 100644 --- a/themes/clean-detailed.omp.json +++ b/themes/clean-detailed.omp.json @@ -143,8 +143,6 @@ "type": "prompt" } ], - "console_title": true, - "console_title_style": "template", "console_title_template": "{{ .Folder }}", "osc99": true, "transient_prompt": { diff --git a/themes/cloud-native-azure.omp.json b/themes/cloud-native-azure.omp.json index d6dbcc04..5a2db987 100644 --- a/themes/cloud-native-azure.omp.json +++ b/themes/cloud-native-azure.omp.json @@ -154,8 +154,6 @@ "type": "prompt" } ], - "console_title": true, - "console_title_style": "template", "console_title_template": "{{ .Shell }} in {{ .Folder }}", "final_space": true, "version": 1 diff --git a/themes/craver.omp.json b/themes/craver.omp.json index de1d963b..afdccc59 100644 --- a/themes/craver.omp.json +++ b/themes/craver.omp.json @@ -114,8 +114,6 @@ "type": "prompt" } ], - "console_title": true, - "console_title_style": "template", "console_title_template": "{{if .Root}}(Admin) {{end}}{{.Folder}}", "version": 1 } diff --git a/themes/free-ukraine.omp.json b/themes/free-ukraine.omp.json index a835dfc2..ff96a29d 100644 --- a/themes/free-ukraine.omp.json +++ b/themes/free-ukraine.omp.json @@ -18,7 +18,7 @@ }, { "alignment": "left", - "segments": [ + "segments": [ { "foreground": "#0057b7", "properties": { @@ -42,18 +42,18 @@ "foreground": "#FBD951", "properties": { "home_icon": "\uf7dd", - "style": "mixed", + "style": "mixed", "template": "{{ .Path }} " }, "style": "diamond", "trailing_diamond": "\ue0b0", "type": "path" - }, + }, { "background": "#0057b7", "foreground": "#ffd700", "powerline_symbol": "\ue0b0", - "properties": { + "properties": { "fetch_stash_count": true, "fetch_status": true, "fetch_upstream_icon": true, @@ -72,7 +72,7 @@ ], "foreground": "#0057b7", "powerline_symbol": "\ue0b0", - "properties": { + "properties": { "fetch_stash_count": false, "fetch_status": false, "fetch_upstream_icon": false, @@ -89,7 +89,7 @@ "style": "plain", "trailing_diamond": "\ue0b0", "type": "text" - }, + }, { "foreground": "#0057b7", "foreground_templates": [ @@ -104,7 +104,7 @@ "style": "diamond", "trailing_diamond": "\ue0b0", "type": "exit" - } + } ], "type": "prompt" }, @@ -112,7 +112,7 @@ "alignment": "right", "segments": [ { - "background": "#0057b7", + "background": "#0057b7", "foreground": "#FBD951", "leading_diamond": "\ue0b6", "properties": { @@ -194,7 +194,7 @@ }, "style": "powerline", "type": "root" - }, + }, { "background": "#FBD951", "foreground": "#0057b7", @@ -205,7 +205,7 @@ }, "style": "powerline", "type": "session" - } + } ], "type": "prompt" }, @@ -248,8 +248,6 @@ "type": "rprompt" } ], - "console_title": true, - "console_title_style": "template", "console_title_template": "{{if .Root}}Admin: {{end}} {{.Folder}}", "final_space": true, "version": 1 diff --git a/themes/grandpa-style.omp.json b/themes/grandpa-style.omp.json index 6f84d984..42216321 100644 --- a/themes/grandpa-style.omp.json +++ b/themes/grandpa-style.omp.json @@ -125,8 +125,6 @@ "type": "prompt" } ], - "console_title": true, - "console_title_style": "template", "console_title_template": "{{if .Root}} \u26a1 {{end}}{{.Folder | replace \"~\" \"🏚\" }} @ {{.HostName}}", "osc99": true, "version": 1 diff --git a/themes/hotstick.minimal.omp.json b/themes/hotstick.minimal.omp.json index c43b7a52..6ad90e16 100644 --- a/themes/hotstick.minimal.omp.json +++ b/themes/hotstick.minimal.omp.json @@ -53,8 +53,6 @@ "type": "prompt" } ], - "console_title": true, - "console_title_style": "template", "console_title_template": "{{.Folder}}{{if .Root}} :: root{{end}} :: {{.Shell}}", "final_space": true, "osc99": true, diff --git a/themes/if_tea.omp.json b/themes/if_tea.omp.json index ff922e6d..246661d1 100644 --- a/themes/if_tea.omp.json +++ b/themes/if_tea.omp.json @@ -170,8 +170,6 @@ "type": "prompt" } ], - "console_title": true, - "console_title_style": "template", "console_title_template": "{{ .Folder }}", "osc99": true, "transient_prompt": { diff --git a/themes/iterm2.omp.json b/themes/iterm2.omp.json index 47986d77..de449366 100644 --- a/themes/iterm2.omp.json +++ b/themes/iterm2.omp.json @@ -142,8 +142,6 @@ "type": "prompt" } ], - "console_title": true, - "console_title_style": "template", "console_title_template": "{{ .Shell }} in {{ .Folder }}", "final_space": true, "transient_prompt": { diff --git a/themes/jandedobbeleer.omp.json b/themes/jandedobbeleer.omp.json index 3b84c0b7..7da9b61d 100644 --- a/themes/jandedobbeleer.omp.json +++ b/themes/jandedobbeleer.omp.json @@ -229,8 +229,6 @@ "type": "rprompt" } ], - "console_title": true, - "console_title_style": "template", "console_title_template": "{{ .Shell }} in {{ .Folder }}", "final_space": true, "version": 1 diff --git a/themes/jblab_2021.omp.json b/themes/jblab_2021.omp.json index d6297681..d848ec20 100644 --- a/themes/jblab_2021.omp.json +++ b/themes/jblab_2021.omp.json @@ -100,8 +100,6 @@ "type": "prompt" } ], - "console_title": true, - "console_title_style": "template", "console_title_template": "{{if .Root}} \u26a1 {{end}}{{.Folder | replace \"~\" \"🏠\"}} @ {{.HostName}}", "final_space": true, "osc99": true, diff --git a/themes/jonnychipz.omp.json b/themes/jonnychipz.omp.json index 6aba4e0e..dd4d7c3a 100644 --- a/themes/jonnychipz.omp.json +++ b/themes/jonnychipz.omp.json @@ -157,8 +157,6 @@ "type": "prompt" } ], - "console_title": true, - "console_title_style": "template", "console_title_template": "{{if .Root}}root :: {{end}}{{.Shell}} :: {{.Folder}}", "final_space": true, "version": 1 diff --git a/themes/jv_sitecorian.omp.json b/themes/jv_sitecorian.omp.json index dc95d2fc..854314da 100644 --- a/themes/jv_sitecorian.omp.json +++ b/themes/jv_sitecorian.omp.json @@ -181,8 +181,6 @@ "type": "rprompt" } ], - "console_title": true, - "console_title_style": "template", "console_title_template": "{{if .Root}}Admin: {{end}} {{.Folder}}", "final_space": true, "version": 1 diff --git a/themes/larserikfinholt.omp.json b/themes/larserikfinholt.omp.json index 0e091031..a7b161b1 100644 --- a/themes/larserikfinholt.omp.json +++ b/themes/larserikfinholt.omp.json @@ -98,8 +98,6 @@ "type": "prompt" } ], - "console_title": true, - "console_title_style": "template", "console_title_template": "{{ .Shell }} in {{ .Folder }}", "final_space": true, "version": 1 diff --git a/themes/markbull.omp.json b/themes/markbull.omp.json index d30987b0..5211d94e 100644 --- a/themes/markbull.omp.json +++ b/themes/markbull.omp.json @@ -123,8 +123,6 @@ "type": "prompt" } ], - "console_title": true, - "console_title_style": "template", "console_title_template": "{{if .Root}}\u26a1 {{end}}{{.Folder}}", "final_space": true, "osc99": true, diff --git a/themes/mojada.omp.json b/themes/mojada.omp.json index 75f40324..cb0d83a1 100644 --- a/themes/mojada.omp.json +++ b/themes/mojada.omp.json @@ -144,8 +144,6 @@ "type": "rprompt" } ], - "console_title": true, - "console_title_style": "template", "console_title_template": "{{.UserName}}@{{.HostName}} : {{.Folder}}", "final_space": true, "version": 1 diff --git a/themes/night-owl.omp.json b/themes/night-owl.omp.json index ffa0cb4d..e7ed0056 100644 --- a/themes/night-owl.omp.json +++ b/themes/night-owl.omp.json @@ -317,8 +317,6 @@ "type": "prompt" } ], - "console_title": true, - "console_title_style": "template", "console_title_template": "{{ .Folder }}", "osc99": true, "transient_prompt": { diff --git a/themes/nu4a.omp.json b/themes/nu4a.omp.json index 92df0603..f1a2df68 100644 --- a/themes/nu4a.omp.json +++ b/themes/nu4a.omp.json @@ -93,8 +93,6 @@ "foreground": "#100e23", "template": " \uf061 " }, - "console_title": true, - "console_title_style": "template", "console_title_template": "{{if .Root}} \u26a1 {{end}}{{.UserName}} \u2794 📁{{.Folder}}", "final_space": true, "version": 1 diff --git a/themes/pixelrobots.omp.json b/themes/pixelrobots.omp.json index e98004d9..97c302af 100644 --- a/themes/pixelrobots.omp.json +++ b/themes/pixelrobots.omp.json @@ -153,8 +153,6 @@ "type": "prompt" } ], - "console_title": true, - "console_title_style": "template", "console_title_template": "{{if .Root}}root :: {{end}}{{.Shell}} :: {{.Folder}}", "final_space": true, "version": 1 diff --git a/themes/powerlevel10k_rainbow.omp.json b/themes/powerlevel10k_rainbow.omp.json index d8a8f930..6fef39c9 100644 --- a/themes/powerlevel10k_rainbow.omp.json +++ b/themes/powerlevel10k_rainbow.omp.json @@ -222,8 +222,6 @@ "type": "rprompt" } ], - "console_title": true, - "console_title_style": "template", "console_title_template": "{{ .Shell }} in {{ .Folder }}", "final_space": true, "version": 1 diff --git a/themes/pure.omp.json b/themes/pure.omp.json index 73fba586..d0d54884 100644 --- a/themes/pure.omp.json +++ b/themes/pure.omp.json @@ -80,8 +80,6 @@ "type": "prompt" } ], - "console_title": true, - "console_title_style": "template", "console_title_template": "{{if .Root}}(Admin){{end}} {{.PWD}}", "version": 1 } diff --git a/themes/schema.json b/themes/schema.json index 6953e5e6..c256279b 100644 --- a/themes/schema.json +++ b/themes/schema.json @@ -2112,19 +2112,6 @@ "description": "https://ohmyposh.dev/docs/config-overview#general-settings", "default": false }, - "console_title": { - "type": "boolean", - "title": "Console Title", - "description": "https://ohmyposh.dev/docs/config-overview#general-settings", - "default": true - }, - "console_title_style": { - "type": "string", - "title": "Console Title Style", - "description": "https://ohmyposh.dev/docs/config-title#console-title-style", - "enum": ["folder", "path", "template"], - "default": "folder" - }, "console_title_template": { "type": "string", "title": "Console Title Template", diff --git a/themes/slim.omp.json b/themes/slim.omp.json index b80f3460..d12a27b2 100644 --- a/themes/slim.omp.json +++ b/themes/slim.omp.json @@ -196,8 +196,6 @@ "type": "rprompt" } ], - "console_title": true, - "console_title_style": "template", "console_title_template": "{{if .Root}}root :: {{end}}{{.Shell}} :: {{.Folder}}", "final_space": true, "version": 1 diff --git a/themes/slimfat.omp.json b/themes/slimfat.omp.json index e3768bec..5131fa08 100644 --- a/themes/slimfat.omp.json +++ b/themes/slimfat.omp.json @@ -194,8 +194,6 @@ "type": "rprompt" } ], - "console_title": true, - "console_title_style": "template", "console_title_template": "{{if .Root}}root :: {{end}}{{.Shell}} :: {{.Folder}}", "final_space": true, "version": 1 diff --git a/themes/thecyberden.omp.json b/themes/thecyberden.omp.json index 6607816b..ff9435c3 100644 --- a/themes/thecyberden.omp.json +++ b/themes/thecyberden.omp.json @@ -112,6 +112,6 @@ "type": "prompt" } ], - "console_title_style": "folder", + "console_title_template": "{{ .Folder }}", "version": 1 -} \ No newline at end of file +} diff --git a/themes/unicorn.omp.json b/themes/unicorn.omp.json index 633f7947..ac9a46cf 100644 --- a/themes/unicorn.omp.json +++ b/themes/unicorn.omp.json @@ -95,8 +95,6 @@ "type": "prompt" } ], - "console_title": true, - "console_title_style": "template", "console_title_template": "{{.UserName}}@{{.HostName}} in {{ .PWD }}", "final_space": true, "version": 1 diff --git a/themes/velvet.omp.json b/themes/velvet.omp.json index ed660fe2..b024353c 100644 --- a/themes/velvet.omp.json +++ b/themes/velvet.omp.json @@ -164,8 +164,6 @@ "type": "prompt" } ], - "console_title": true, - "console_title_style": "template", "console_title_template": "{{ .Shell }} - {{ .Folder }}", "final_space": true, "osc99": true,