mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-01-21 16:11:20 -08:00
refactor: remove terminal lock
This commit is contained in:
parent
38452b92a8
commit
b5afe0edaf
|
@ -14,7 +14,6 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/jandedobbeleer/oh-my-posh/src/cache"
|
"github.com/jandedobbeleer/oh-my-posh/src/cache"
|
||||||
|
@ -41,11 +40,11 @@ type Terminal struct {
|
||||||
cwd string
|
cwd string
|
||||||
host string
|
host string
|
||||||
networks []*Connection
|
networks []*Connection
|
||||||
sync.RWMutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (term *Terminal) Init() {
|
func (term *Terminal) Init() {
|
||||||
defer term.Trace(time.Now())
|
defer term.Trace(time.Now())
|
||||||
|
|
||||||
if term.CmdFlags == nil {
|
if term.CmdFlags == nil {
|
||||||
term.CmdFlags = &Flags{}
|
term.CmdFlags = &Flags{}
|
||||||
}
|
}
|
||||||
|
@ -70,6 +69,8 @@ func (term *Terminal) Init() {
|
||||||
term.sessionCache = initCache(cache.SessionFileName)
|
term.sessionCache = initCache(cache.SessionFileName)
|
||||||
term.setPromptCount()
|
term.setPromptCount()
|
||||||
|
|
||||||
|
term.setPwd()
|
||||||
|
|
||||||
term.ResolveConfigPath()
|
term.ResolveConfigPath()
|
||||||
|
|
||||||
term.cmdCache = &cache.Command{
|
term.cmdCache = &cache.Command{
|
||||||
|
@ -161,28 +162,35 @@ func (term *Terminal) Getenv(key string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (term *Terminal) Pwd() string {
|
func (term *Terminal) Pwd() string {
|
||||||
term.Lock()
|
return term.cwd
|
||||||
|
}
|
||||||
|
|
||||||
|
func (term *Terminal) setPwd() {
|
||||||
defer term.Trace(time.Now())
|
defer term.Trace(time.Now())
|
||||||
defer term.Unlock()
|
|
||||||
if term.cwd != "" {
|
correctPath := func(pwd string) string {
|
||||||
return term.cwd
|
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 != "" {
|
if term.CmdFlags != nil && term.CmdFlags.PWD != "" {
|
||||||
term.cwd = CleanPath(term, term.CmdFlags.PWD)
|
term.cwd = CleanPath(term, term.CmdFlags.PWD)
|
||||||
term.Debug(term.cwd)
|
term.Debug(term.cwd)
|
||||||
return term.cwd
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
dir, err := os.Getwd()
|
dir, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
term.Error(err)
|
term.Error(err)
|
||||||
return ""
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
term.cwd = CleanPath(term, dir)
|
term.cwd = correctPath(dir)
|
||||||
term.Debug(term.cwd)
|
term.Debug(term.cwd)
|
||||||
return term.cwd
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (term *Terminal) HasFiles(pattern string) bool {
|
func (term *Terminal) HasFiles(pattern string) bool {
|
||||||
|
@ -213,9 +221,6 @@ func (term *Terminal) HasFilesInDir(dir, pattern string) bool {
|
||||||
|
|
||||||
pattern = strings.ToLower(pattern)
|
pattern = strings.ToLower(pattern)
|
||||||
|
|
||||||
term.RWMutex.RLock()
|
|
||||||
defer term.RWMutex.RUnlock()
|
|
||||||
|
|
||||||
for _, match := range dirEntries {
|
for _, match := range dirEntries {
|
||||||
if match.IsDir() {
|
if match.IsDir() {
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in a new issue