mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-01-14 12:48:04 -08:00
feat(init): add --debug flag
This commit is contained in:
parent
9e73b15a3b
commit
1a7f2d2d10
6
src/cache/file.go
vendored
6
src/cache/file.go
vendored
|
@ -21,10 +21,12 @@ func (fc *File) Init(cacheFilePath string) {
|
||||||
fc.cache = maps.NewConcurrent()
|
fc.cache = maps.NewConcurrent()
|
||||||
fc.cacheFilePath = cacheFilePath
|
fc.cacheFilePath = cacheFilePath
|
||||||
|
|
||||||
log.Debug("Loading cache file:", fc.cacheFilePath)
|
log.Debug("loading cache file:", fc.cacheFilePath)
|
||||||
|
|
||||||
content, err := os.ReadFile(fc.cacheFilePath)
|
content, err := os.ReadFile(fc.cacheFilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
// set to dirty so we create it on close
|
||||||
|
fc.dirty = true
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -39,7 +41,7 @@ func (fc *File) Init(cacheFilePath string) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debug("Loading cache key:", key)
|
log.Debug("loading cache key:", key)
|
||||||
fc.cache.Set(key, co)
|
fc.cache.Set(key, co)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,11 @@ package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/jandedobbeleer/oh-my-posh/src/config"
|
"github.com/jandedobbeleer/oh-my-posh/src/config"
|
||||||
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
|
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
|
||||||
"github.com/jandedobbeleer/oh-my-posh/src/shell"
|
"github.com/jandedobbeleer/oh-my-posh/src/shell"
|
||||||
"github.com/jandedobbeleer/oh-my-posh/src/upgrade"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
@ -52,34 +52,36 @@ func init() {
|
||||||
initCmd.Flags().BoolVarP(&printOutput, "print", "p", false, "print the init script")
|
initCmd.Flags().BoolVarP(&printOutput, "print", "p", false, "print the init script")
|
||||||
initCmd.Flags().BoolVarP(&strict, "strict", "s", false, "run in strict mode")
|
initCmd.Flags().BoolVarP(&strict, "strict", "s", false, "run in strict mode")
|
||||||
initCmd.Flags().BoolVarP(&manual, "manual", "m", false, "enable/disable manual mode")
|
initCmd.Flags().BoolVarP(&manual, "manual", "m", false, "enable/disable manual mode")
|
||||||
|
initCmd.Flags().BoolVar(&debug, "debug", false, "enable/disable debug mode")
|
||||||
_ = initCmd.MarkPersistentFlagRequired("config")
|
_ = initCmd.MarkPersistentFlagRequired("config")
|
||||||
RootCmd.AddCommand(initCmd)
|
RootCmd.AddCommand(initCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func runInit(shellName string) {
|
func runInit(shellName string) {
|
||||||
|
var startTime time.Time
|
||||||
|
if debug {
|
||||||
|
startTime = time.Now()
|
||||||
|
}
|
||||||
|
|
||||||
env := &runtime.Terminal{
|
env := &runtime.Terminal{
|
||||||
CmdFlags: &runtime.Flags{
|
CmdFlags: &runtime.Flags{
|
||||||
Shell: shellName,
|
Shell: shellName,
|
||||||
Config: configFlag,
|
Config: configFlag,
|
||||||
Strict: strict,
|
Strict: strict,
|
||||||
Manual: manual,
|
Manual: manual,
|
||||||
|
Debug: debug,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
env.Init()
|
env.Init()
|
||||||
defer env.Close()
|
defer env.Close()
|
||||||
|
|
||||||
cfg := config.Load(env)
|
cfg := config.Load(env)
|
||||||
|
|
||||||
// TODO: this can be removed I think
|
|
||||||
// allow overriding the upgrade notice from the config
|
|
||||||
if cfg.DisableNotice || cfg.AutoUpgrade {
|
|
||||||
env.Cache().Set(upgrade.CACHEKEY, "disabled", -1)
|
|
||||||
}
|
|
||||||
|
|
||||||
feats := cfg.Features()
|
feats := cfg.Features()
|
||||||
|
|
||||||
if printOutput {
|
if printOutput || debug {
|
||||||
init := shell.PrintInit(env, feats)
|
init := shell.PrintInit(env, feats, &startTime)
|
||||||
fmt.Print(init)
|
fmt.Print(init)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,7 +112,7 @@ func (segment *Segment) SetEnabled(env runtime.Environment) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
segment.env.DebugF("Segment: %s", segment.Name())
|
segment.env.DebugF("segment: %s", segment.Name())
|
||||||
|
|
||||||
// validate toggles
|
// validate toggles
|
||||||
if toggles, OK := segment.env.Session().Get(cache.TOGGLECACHE); OK && len(toggles) > 0 {
|
if toggles, OK := segment.env.Session().Get(cache.TOGGLECACHE); OK && len(toggles) > 0 {
|
||||||
|
|
|
@ -20,7 +20,7 @@ func (e *Engine) PrintDebug(startTime time.Time, version string) string {
|
||||||
|
|
||||||
// console title timing
|
// console title timing
|
||||||
titleStartTime := time.Now()
|
titleStartTime := time.Now()
|
||||||
e.Env.Debug("Segment: Title")
|
e.Env.Debug("segment: Title")
|
||||||
title := e.getTitleTemplateText()
|
title := e.getTitleTemplateText()
|
||||||
consoleTitle := &config.Segment{
|
consoleTitle := &config.Segment{
|
||||||
Alias: "ConsoleTitle",
|
Alias: "ConsoleTitle",
|
||||||
|
|
|
@ -225,10 +225,12 @@ func (term *Terminal) Init() {
|
||||||
|
|
||||||
if term.CmdFlags.Debug {
|
if term.CmdFlags.Debug {
|
||||||
log.Enable()
|
log.Enable()
|
||||||
|
log.Debug("debug mode enabled")
|
||||||
}
|
}
|
||||||
|
|
||||||
if term.CmdFlags.Plain {
|
if term.CmdFlags.Plain {
|
||||||
log.Plain()
|
log.Plain()
|
||||||
|
log.Debug("dlain mode enabled")
|
||||||
}
|
}
|
||||||
|
|
||||||
initCache := func(fileName string) *cache.File {
|
initCache := func(fileName string) *cache.File {
|
||||||
|
@ -256,13 +258,13 @@ func (term *Terminal) resolveConfigPath() {
|
||||||
defer term.Trace(time.Now())
|
defer term.Trace(time.Now())
|
||||||
|
|
||||||
if poshTheme := term.Getenv("POSH_THEME"); len(poshTheme) > 0 {
|
if poshTheme := term.Getenv("POSH_THEME"); len(poshTheme) > 0 {
|
||||||
term.DebugF("Config set using POSH_THEME: %s", poshTheme)
|
term.DebugF("config set using POSH_THEME: %s", poshTheme)
|
||||||
term.CmdFlags.Config = poshTheme
|
term.CmdFlags.Config = poshTheme
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(term.CmdFlags.Config) == 0 {
|
if len(term.CmdFlags.Config) == 0 {
|
||||||
term.Debug("No config set, fallback to default config")
|
term.Debug("no config set, fallback to default config")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,7 +287,7 @@ func (term *Terminal) resolveConfigPath() {
|
||||||
// Cygwin path always needs the full path as we're on Windows but not really.
|
// Cygwin path always needs the full path as we're on Windows but not really.
|
||||||
// Doing filepath actions will convert it to a Windows path and break the init script.
|
// Doing filepath actions will convert it to a Windows path and break the init script.
|
||||||
if isCygwin() {
|
if isCygwin() {
|
||||||
term.Debug("Cygwin detected, using full path for config")
|
term.Debug("cygwin detected, using full path for config")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -901,6 +903,8 @@ func dirMatchesOneOf(dir, home, goos string, regexes []string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (term *Terminal) SetPromptCount() {
|
func (term *Terminal) SetPromptCount() {
|
||||||
|
defer term.Trace(time.Now())
|
||||||
|
|
||||||
countStr := os.Getenv("POSH_PROMPT_COUNT")
|
countStr := os.Getenv("POSH_PROMPT_COUNT")
|
||||||
if len(countStr) > 0 {
|
if len(countStr) > 0 {
|
||||||
// this counter is incremented by the shell
|
// this counter is incremented by the shell
|
||||||
|
|
|
@ -42,7 +42,7 @@ func (t *Azd) Enabled() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(parentFilePath) == 0 {
|
if len(parentFilePath) == 0 {
|
||||||
t.env.Debug("No .azure folder found in parent directories")
|
t.env.Debug("no .azure folder found in parent directories")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -353,7 +353,7 @@ func (g *Git) hasWorktree(gitdir *runtime.FileInfo) bool {
|
||||||
matches := regex.FindNamedRegexMatch(`^gitdir: (?P<dir>.*)$`, content)
|
matches := regex.FindNamedRegexMatch(`^gitdir: (?P<dir>.*)$`, content)
|
||||||
|
|
||||||
if matches == nil || len(matches["dir"]) == 0 {
|
if matches == nil || len(matches["dir"]) == 0 {
|
||||||
g.env.Debug("No matches found, directory isn't a worktree")
|
g.env.Debug("no matches found, directory isn't a worktree")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -368,7 +368,7 @@ func (nba *Nba) getResult() (*NBAData, error) {
|
||||||
// Cache the fact a game was not found for 30 minutes so we don't call the API too often
|
// Cache the fact a game was not found for 30 minutes so we don't call the API too often
|
||||||
cacheNotFoundTimeout := nba.props.GetInt(properties.CacheTimeout, 30)
|
cacheNotFoundTimeout := nba.props.GetInt(properties.CacheTimeout, 30)
|
||||||
|
|
||||||
nba.env.Debug("Validating cache data for " + teamName)
|
nba.env.Debug("validating cache data for " + teamName)
|
||||||
|
|
||||||
if cacheScheduleTimeout > 0 {
|
if cacheScheduleTimeout > 0 {
|
||||||
if data, err := nba.getCachedScheduleValue(cachedScheduleKey); err == nil {
|
if data, err := nba.getCachedScheduleValue(cachedScheduleKey); err == nil {
|
||||||
|
@ -382,7 +382,7 @@ func (nba *Nba) getResult() (*NBAData, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nba.env.Debug("Fetching available data for " + teamName)
|
nba.env.Debug("fetching available data for " + teamName)
|
||||||
|
|
||||||
data, err := nba.getAvailableGameData(teamName, httpTimeout)
|
data, err := nba.getAvailableGameData(teamName, httpTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -44,7 +44,7 @@ func (u *Umbraco) Enabled() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(location) == 0 {
|
if len(location) == 0 {
|
||||||
u.env.Debug("No umbraco folder found in parent directories")
|
u.env.Debug("no umbraco folder found in parent directories")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ func (u *Umbraco) Init(props properties.Properties, env runtime.Environment) {
|
||||||
func (u *Umbraco) TryFindModernUmbraco(configPath string) bool {
|
func (u *Umbraco) TryFindModernUmbraco(configPath string) bool {
|
||||||
// Check the passed in filepath is not empty
|
// Check the passed in filepath is not empty
|
||||||
if len(configPath) == 0 {
|
if len(configPath) == 0 {
|
||||||
u.env.Debug("UMBRACO: No .CSProj file path passed in")
|
u.env.Debug("no configPath provided")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +111,6 @@ func (u *Umbraco) TryFindModernUmbraco(configPath string) bool {
|
||||||
err := xml.Unmarshal([]byte(contents), &csProjPackages)
|
err := xml.Unmarshal([]byte(contents), &csProjPackages)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
u.env.Debug("UMBRACO: Error while trying to parse XML of .csproj file")
|
|
||||||
u.env.Debug(err.Error())
|
u.env.Debug(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,7 +130,7 @@ func (u *Umbraco) TryFindModernUmbraco(configPath string) bool {
|
||||||
func (u *Umbraco) TryFindLegacyUmbraco(configPath string) bool {
|
func (u *Umbraco) TryFindLegacyUmbraco(configPath string) bool {
|
||||||
// Check the passed in filepath is not empty
|
// Check the passed in filepath is not empty
|
||||||
if len(configPath) == 0 {
|
if len(configPath) == 0 {
|
||||||
u.env.Debug("UMBRACO: No web.config file path passed in")
|
u.env.Debug("no configPath provided")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,7 +147,6 @@ func (u *Umbraco) TryFindLegacyUmbraco(configPath string) bool {
|
||||||
err := xml.Unmarshal([]byte(contents), &webConfigAppSettings)
|
err := xml.Unmarshal([]byte(contents), &webConfigAppSettings)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
u.env.Debug("UMBRACO: Error while trying to parse XML of web.config file")
|
|
||||||
u.env.Debug(err.Error())
|
u.env.Debug(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,12 +42,12 @@ func (u *Unity) Enabled() bool {
|
||||||
func (u *Unity) GetUnityVersion() (string, error) {
|
func (u *Unity) GetUnityVersion() (string, error) {
|
||||||
projectDir, err := u.env.HasParentFilePath("ProjectSettings", false)
|
projectDir, err := u.env.HasParentFilePath("ProjectSettings", false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
u.env.Debug("No ProjectSettings parent folder found")
|
u.env.Debug("no ProjectSettings parent folder found")
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !u.env.HasFilesInDir(projectDir.Path, "ProjectVersion.txt") {
|
if !u.env.HasFilesInDir(projectDir.Path, "ProjectVersion.txt") {
|
||||||
u.env.Debug("No ProjectVersion.txt file found")
|
u.env.Debug("no ProjectVersion.txt file found")
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,9 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/jandedobbeleer/oh-my-posh/src/log"
|
||||||
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
|
"github.com/jandedobbeleer/oh-my-posh/src/runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -64,7 +66,7 @@ func Init(env runtime.Environment, feats Features) string {
|
||||||
|
|
||||||
return fmt.Sprintf(command, executable, shell, config, additionalParams)
|
return fmt.Sprintf(command, executable, shell, config, additionalParams)
|
||||||
case ZSH, BASH, FISH, CMD, TCSH, XONSH:
|
case ZSH, BASH, FISH, CMD, TCSH, XONSH:
|
||||||
return PrintInit(env, feats)
|
return PrintInit(env, feats, nil)
|
||||||
case NU:
|
case NU:
|
||||||
createNuInit(env, feats)
|
createNuInit(env, feats)
|
||||||
return ""
|
return ""
|
||||||
|
@ -73,7 +75,7 @@ func Init(env runtime.Environment, feats Features) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func PrintInit(env runtime.Environment, features Features) string {
|
func PrintInit(env runtime.Environment, features Features, startTime *time.Time) string {
|
||||||
executable, err := getExecutablePath(env)
|
executable, err := getExecutablePath(env)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return noExe
|
return noExe
|
||||||
|
@ -127,5 +129,21 @@ func PrintInit(env runtime.Environment, features Features) string {
|
||||||
"::SHELL::", shell,
|
"::SHELL::", shell,
|
||||||
).Replace(script)
|
).Replace(script)
|
||||||
|
|
||||||
return features.Lines(shell).String(init)
|
shellScript := features.Lines(shell).String(init)
|
||||||
|
|
||||||
|
if !env.Flags().Debug {
|
||||||
|
return shellScript
|
||||||
|
}
|
||||||
|
|
||||||
|
var builder strings.Builder
|
||||||
|
|
||||||
|
builder.WriteString(fmt.Sprintf("\n%s %s\n", log.Text("Init duration:").Green().Bold().Plain(), time.Since(*startTime)))
|
||||||
|
|
||||||
|
builder.WriteString(log.Text("\nScript:\n\n").Green().Bold().Plain().String())
|
||||||
|
builder.WriteString(shellScript)
|
||||||
|
|
||||||
|
builder.WriteString(log.Text("\n\nLogs:\n\n").Green().Bold().Plain().String())
|
||||||
|
builder.WriteString(env.Logs())
|
||||||
|
|
||||||
|
return builder.String()
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ func createNuInit(env runtime.Environment, features Features) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = f.WriteString(PrintInit(env, features))
|
_, err = f.WriteString(PrintInit(env, features, nil))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ func (c *Context) init(t *Text) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Text) Render() (string, error) {
|
func (t *Text) Render() (string, error) {
|
||||||
t.Env.DebugF("Rendering template: %s", t.Template)
|
t.Env.DebugF("rendering template: %s", t.Template)
|
||||||
|
|
||||||
shell = t.Env.Flags().Shell
|
shell = t.Env.Flags().Shell
|
||||||
|
|
||||||
|
|
|
@ -102,8 +102,8 @@ func Init(sh string) {
|
||||||
Shell = sh
|
Shell = sh
|
||||||
Program = getTerminalName()
|
Program = getTerminalName()
|
||||||
|
|
||||||
log.Debug("Terminal shell:", Shell)
|
log.Debug("terminal program:", Program)
|
||||||
log.Debug("Terminal program:", Program)
|
log.Debug("terminal shell:", Shell)
|
||||||
|
|
||||||
color.TrueColor = Program != AppleTerminal
|
color.TrueColor = Program != AppleTerminal
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue