From b5afe0edaf9a91bc029fa79968eab699fc9c00a2 Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Sun, 25 Aug 2024 20:59:26 +0200 Subject: [PATCH] refactor: remove terminal lock --- src/runtime/terminal.go | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/runtime/terminal.go b/src/runtime/terminal.go index 279c6d79..8dfe6102 100644 --- a/src/runtime/terminal.go +++ b/src/runtime/terminal.go @@ -14,7 +14,6 @@ import ( "runtime" "strconv" "strings" - "sync" "time" "github.com/jandedobbeleer/oh-my-posh/src/cache" @@ -41,11 +40,11 @@ type Terminal struct { cwd string host string networks []*Connection - sync.RWMutex } func (term *Terminal) Init() { defer term.Trace(time.Now()) + if term.CmdFlags == nil { term.CmdFlags = &Flags{} } @@ -70,6 +69,8 @@ func (term *Terminal) Init() { term.sessionCache = initCache(cache.SessionFileName) term.setPromptCount() + term.setPwd() + term.ResolveConfigPath() term.cmdCache = &cache.Command{ @@ -161,28 +162,35 @@ func (term *Terminal) Getenv(key string) string { } func (term *Terminal) Pwd() string { - term.Lock() + return term.cwd +} + +func (term *Terminal) setPwd() { defer term.Trace(time.Now()) - defer term.Unlock() - if term.cwd != "" { - return term.cwd + + correctPath := func(pwd string) string { + if term.GOOS() != WINDOWS { + return pwd + } + // on Windows, and being case sensitive and not consistent and all, this gives silly issues + driveLetter := regex.GetCompiledRegex(`^[a-z]:`) + return driveLetter.ReplaceAllStringFunc(pwd, strings.ToUpper) } if term.CmdFlags != nil && term.CmdFlags.PWD != "" { term.cwd = CleanPath(term, term.CmdFlags.PWD) term.Debug(term.cwd) - return term.cwd + return } dir, err := os.Getwd() if err != nil { term.Error(err) - return "" + return } - term.cwd = CleanPath(term, dir) + term.cwd = correctPath(dir) term.Debug(term.cwd) - return term.cwd } func (term *Terminal) HasFiles(pattern string) bool { @@ -213,9 +221,6 @@ func (term *Terminal) HasFilesInDir(dir, pattern string) bool { pattern = strings.ToLower(pattern) - term.RWMutex.RLock() - defer term.RWMutex.RUnlock() - for _, match := range dirEntries { if match.IsDir() { continue