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