mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-28 20:39:40 -08:00
feat: use tilde in console title
This commit is contained in:
parent
369ff4ddaf
commit
0761c04286
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -39,13 +40,13 @@ func (t *consoleTitle) getConsoleTitle() string {
|
||||||
var title string
|
var title string
|
||||||
switch t.settings.ConsoleTitleStyle {
|
switch t.settings.ConsoleTitleStyle {
|
||||||
case FullPath:
|
case FullPath:
|
||||||
title = t.env.getcwd()
|
title = t.getPwd()
|
||||||
case Template:
|
case Template:
|
||||||
title = t.getTemplateText()
|
title = t.getTemplateText()
|
||||||
case FolderName:
|
case FolderName:
|
||||||
fallthrough
|
fallthrough
|
||||||
default:
|
default:
|
||||||
title = base(t.env.getcwd(), t.env)
|
title = base(t.getPwd(), t.env)
|
||||||
}
|
}
|
||||||
return fmt.Sprintf(t.formats.title, title)
|
return fmt.Sprintf(t.formats.title, title)
|
||||||
}
|
}
|
||||||
|
@ -53,8 +54,8 @@ func (t *consoleTitle) getConsoleTitle() string {
|
||||||
func (t *consoleTitle) getTemplateText() string {
|
func (t *consoleTitle) getTemplateText() string {
|
||||||
context := &TitleTemplateContext{
|
context := &TitleTemplateContext{
|
||||||
Root: t.env.isRunningAsRoot(),
|
Root: t.env.isRunningAsRoot(),
|
||||||
Path: t.env.getcwd(),
|
Path: t.getPwd(),
|
||||||
Folder: base(t.env.getcwd(), t.env),
|
Folder: base(t.getPwd(), t.env),
|
||||||
Shell: t.env.getShellName(),
|
Shell: t.env.getShellName(),
|
||||||
}
|
}
|
||||||
tmpl, err := template.New("title").Parse(t.settings.ConsoleTitleTemplate)
|
tmpl, err := template.New("title").Parse(t.settings.ConsoleTitleTemplate)
|
||||||
|
@ -69,3 +70,9 @@ func (t *consoleTitle) getTemplateText() string {
|
||||||
}
|
}
|
||||||
return buffer.String()
|
return buffer.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *consoleTitle) getPwd() string {
|
||||||
|
pwd := t.env.getcwd()
|
||||||
|
pwd = strings.Replace(pwd, t.env.homeDir(), "~", 1)
|
||||||
|
return pwd
|
||||||
|
}
|
||||||
|
|
|
@ -16,8 +16,8 @@ func TestGetConsoleTitle(t *testing.T) {
|
||||||
ShellName string
|
ShellName string
|
||||||
Expected string
|
Expected string
|
||||||
}{
|
}{
|
||||||
{Style: FolderName, Cwd: "/usr/home", PathSeperator: "/", ShellName: "default", Expected: "\x1b]0;home\a"},
|
{Style: FolderName, Cwd: "/usr/home", PathSeperator: "/", ShellName: "default", Expected: "\x1b]0;~\a"},
|
||||||
{Style: FullPath, Cwd: "/usr/home/jan", PathSeperator: "/", ShellName: "default", Expected: "\x1b]0;/usr/home/jan\a"},
|
{Style: FullPath, Cwd: "/usr/home/jan", PathSeperator: "/", ShellName: "default", Expected: "\x1b]0;~/jan\a"},
|
||||||
{
|
{
|
||||||
Style: Template,
|
Style: Template,
|
||||||
Template: "{{.Path}}{{if .Root}} :: Admin{{end}} :: {{.Shell}}",
|
Template: "{{.Path}}{{if .Root}} :: Admin{{end}} :: {{.Shell}}",
|
||||||
|
|
Loading…
Reference in a new issue