Repository: JanDeDobbeleer/oh-my-posh
Pull request #1620 (2022-01-20 12:36:39)

log env data
### Prerequisites

- [x] I have read and understood the `CONTRIBUTING` guide
- [x] The commit message follows the [conventional commits][cc] guidelines
- [x] Tests for the changes have been added (for bug fixes/features)
- [x] Docs have been added / updated (for bug fixes/features)

### Description

- feat: log directories on debug
- refactor: rename getcwd to pwd


<!---

Tips:

If you're not comfortable with working with Git, we're working a guide (https://ohmyposh.dev/docs/contributing_git) to help you out.
Oh My Posh advises GitKraken (https://www.gitkraken.com/invite/nQmDPR9D) as your preferred cross platform Git GUI power tool.

-->

[cc]: https://www.conventionalcommits.org/en/v1.0.0/#summary



Patch:
diff --git a/src/console_title.go b/src/console_title.go
index 5c6fae25..7d4f59e2 100644
--- a/src/console_title.go
+++ b/src/console_title.go
@@ -51,7 +51,7 @@ func (t *consoleTitle) getTemplateText() string {
 }
 
 func (t *consoleTitle) getPwd() string {
-	pwd := t.env.getcwd()
+	pwd := t.env.pwd()
 	pwd = strings.Replace(pwd, t.env.homeDir(), "~", 1)
 	return pwd
 }
diff --git a/src/engine.go b/src/engine.go
index d700f02a..51301ab4 100644
--- a/src/engine.go
+++ b/src/engine.go
@@ -66,7 +66,7 @@ func (e *engine) render() string {
 	if !e.config.OSC99 {
 		return e.print()
 	}
-	cwd := e.env.getcwd()
+	cwd := e.env.pwd()
 	e.writeANSI(e.ansi.consolePwd(cwd))
 	return e.print()
 }
diff --git a/src/environment.go b/src/environment.go
index 32779b6c..6d450b49 100644
--- a/src/environment.go
+++ b/src/environment.go
@@ -90,7 +90,7 @@ type wifiInfo struct {
 
 type Environment interface {
 	getenv(key string) string
-	getcwd() string
+	pwd() string
 	homeDir() string
 	hasFiles(pattern string) bool
 	hasFilesInDir(dir, pattern string) bool
@@ -224,8 +224,11 @@ func (env *environment) getenv(key string) string {
 	return val
 }
 
-func (env *environment) getcwd() string {
-	defer env.trace(time.Now(), "getcwd")
+func (env *environment) pwd() string {
+	defer env.trace(time.Now(), "pwd")
+	defer func() {
+		env.log(Error, "pwd", env.cwd)
+	}()
 	if env.cwd != "" {
 		return env.cwd
 	}
@@ -240,7 +243,7 @@ func (env *environment) getcwd() string {
 	}
 	dir, err := os.Getwd()
 	if err != nil {
-		env.log(Error, "getcwd", err.Error())
+		env.log(Error, "pwd", err.Error())
 		return ""
 	}
 	env.cwd = correctPath(dir)
@@ -249,7 +252,7 @@ func (env *environment) getcwd() string {
 
 func (env *environment) hasFiles(pattern string) bool {
 	defer env.trace(time.Now(), "hasFiles", pattern)
-	cwd := env.getcwd()
+	cwd := env.pwd()
 	pattern = cwd + env.getPathSeperator() + pattern
 	matches, err := filepath.Glob(pattern)
 	if err != nil {
@@ -503,7 +506,7 @@ func (env *environment) HTTPRequest(url string, timeout int, requestModifiers ..
 
 func (env *environment) hasParentFilePath(path string) (*fileInfo, error) {
 	defer env.trace(time.Now(), "hasParentFilePath", path)
-	currentFolder := env.getcwd()
+	currentFolder := env.pwd()
 	for {
 		searchPath := filepath.Join(currentFolder, path)
 		info, err := os.Stat(searchPath)
@@ -568,7 +571,7 @@ func (env *environment) templateCache() *templateCache {
 		val := splitted[1:]
 		tmplCache.Env[key] = strings.Join(val, separator)
 	}
-	pwd := env.getcwd()
+	pwd := env.pwd()
 	pwd = strings.Replace(pwd, env.homeDir(), "~", 1)
 	tmplCache.PWD = pwd
 	tmplCache.Folder = base(pwd, env)
diff --git a/src/environment_unix.go b/src/environment_unix.go
index 739364f5..b26c66b2 100644
--- a/src/environment_unix.go
+++ b/src/environment_unix.go
@@ -87,7 +87,7 @@ func (env *environment) getWindowsRegistryKeyValue(path string) (*windowsRegistr
 }
 
 func (env *environment) inWSLSharedDrive() bool {
-	return env.isWsl() && strings.HasPrefix(env.getcwd(), "/mnt/")
+	return env.isWsl() && strings.HasPrefix(env.pwd(), "/mnt/")
 }
 
 func (env *environment) convertToWindowsPath(path string) string {
diff --git a/src/environment_windows.go b/src/environment_windows.go
index 6d77f3d6..2f26b5b7 100644
--- a/src/environment_windows.go
+++ b/src/environment_windows.go
@@ -55,6 +55,9 @@ func (env *environment) isRunningAsRoot() bool {
 
 func (env *environment) homeDir() string {
 	home := os.Getenv("HOME")
+	defer func() {
+		env.log(Error, "homeDir", home)
+	}()
 	if len(home) > 0 {
 		return home
 	}
diff --git a/src/segment.go b/src/segment.go
index 8a57f8fd..355e18b9 100644
--- a/src/segment.go
+++ b/src/segment.go
@@ -198,7 +198,7 @@ func (segment *Segment) cwdIncluded() bool {
 		return true
 	}
 
-	return dirMatchesOneOf(segment.env, segment.env.getcwd(), list)
+	return dirMatchesOneOf(segment.env, segment.env.pwd(), list)
 }
 
 func (segment *Segment) cwdExcluded() bool {
@@ -207,7 +207,7 @@ func (segment *Segment) cwdExcluded() bool {
 		value = segment.Properties[IgnoreFolders]
 	}
 	list := parseStringArray(value)
-	return dirMatchesOneOf(segment.env, segment.env.getcwd(), list)
+	return dirMatchesOneOf(segment.env, segment.env.pwd(), list)
 }
 
 func (segment *Segment) getColor(templates []string, defaultColor string) string {
diff --git a/src/segment_angular.go b/src/segment_angular.go
index c83080ca..149d2452 100644
--- a/src/segment_angular.go
+++ b/src/segment_angular.go
@@ -24,13 +24,13 @@ func (a *angular) init(props Properties, env Environment) {
 				getVersion: func() (string, error) {
 					const fileName string = "package.json"
 					const fileFolder string = "/node_modules/@angular/core"
-					angularFilePath := a.language.env.getcwd() + fileFolder
+					angularFilePath := a.language.env.pwd() + fileFolder
 					if !a.language.env.hasFilesInDir(angularFilePath, fileName) {
 						return "", fmt.Errorf("%s not found in %s", fileName, angularFilePath)
 					}
 					// parse file
 					objmap := map[string]json.RawMessage{}
-					content := a.language.env.getFileContent(a.language.env.getcwd() + fileFolder + "/" + fileName)
+					content := a.language.env.getFileContent(a.language.env.pwd() + fileFolder + "/" + fileName)
 					err := json.Unmarshal([]byte(content), &objmap)
 					if err != nil {
 						return "", err
diff --git a/src/segment_language.go b/src/segment_language.go
index 64071323..396a2b19 100644
--- a/src/segment_language.go
+++ b/src/segment_language.go
@@ -126,7 +126,7 @@ func (l *language) enabled() bool {
 	l.extensions = l.props.getStringArray(LanguageExtensions, l.extensions)
 
 	inHomeDir := func() bool {
-		return l.env.getcwd() == l.env.homeDir()
+		return l.env.pwd() == l.env.homeDir()
 	}
 	homeEnabled := l.props.getBool(HomeEnabled, l.homeEnabled)
 	if inHomeDir() && !homeEnabled {
diff --git a/src/segment_path.go b/src/segment_path.go
index 0a25fac2..7dfda3fe 100644
--- a/src/segment_path.go
+++ b/src/segment_path.go
@@ -58,7 +58,7 @@ func (pt *path) enabled() bool {
 }
 
 func (pt *path) string() string {
-	pt.pwd = pt.env.getcwd()
+	pt.pwd = pt.env.pwd()
 	switch style := pt.props.getString(Style, Agnoster); style {
 	case Agnoster:
 		pt.Path = pt.getAgnosterPath()
@@ -259,7 +259,7 @@ func (pt *path) getFolderPath() string {
 func (pt *path) getPwd() string {
 	pwd := *pt.env.getArgs().PSWD
 	if pwd == "" {
-		pwd = pt.env.getcwd()
+		pwd = pt.env.pwd()
 	}
 	pwd = pt.replaceMappedLocations(pwd)
 	return pwd
diff --git a/src/segment_terraform.go b/src/segment_terraform.go
index 8ef12d55..6811635c 100644
--- a/src/segment_terraform.go
+++ b/src/segment_terraform.go
@@ -27,7 +27,7 @@ func (tf *terraform) init(props Properties, env Environment) {
 
 func (tf *terraform) enabled() bool {
 	cmd := "terraform"
-	if !tf.env.hasCommand(cmd) || !tf.env.hasFolder(tf.env.getcwd()+"/.terraform") {
+	if !tf.env.hasCommand(cmd) || !tf.env.hasFolder(tf.env.pwd()+"/.terraform") {
 		return false
 	}
 	tf.WorkspaceName, _ = tf.env.runCommand(cmd, "workspace", "show")


Test patch:
diff --git a/src/console_title_test.go b/src/console_title_test.go
index 711d94db..ecc0e665 100644
--- a/src/console_title_test.go
+++ b/src/console_title_test.go
@@ -53,7 +53,7 @@ func TestGetConsoleTitle(t *testing.T) {
 			ConsoleTitleTemplate: tc.Template,
 		}
 		env := new(MockedEnvironment)
-		env.On("getcwd").Return(tc.Cwd)
+		env.On("pwd").Return(tc.Cwd)
 		env.On("homeDir").Return("/usr/home")
 		env.On("getPathSeperator").Return(tc.PathSeperator)
 		env.On("templateCache").Return(&templateCache{
@@ -115,7 +115,7 @@ func TestGetConsoleTitleIfGethostnameReturnsError(t *testing.T) {
 			ConsoleTitleTemplate: tc.Template,
 		}
 		env := new(MockedEnvironment)
-		env.On("getcwd").Return(tc.Cwd)
+		env.On("pwd").Return(tc.Cwd)
 		env.On("homeDir").Return("/usr/home")
 		env.On("templateCache").Return(&templateCache{
 			Env: map[string]string{
diff --git a/src/environment_test.go b/src/environment_test.go
index 654beb60..2f3d2b94 100644
--- a/src/environment_test.go
+++ b/src/environment_test.go
@@ -41,6 +41,6 @@ func TestWindowsPathWithDriveLetter(t *testing.T) {
 				PWD: &tc.CWD,
 			},
 		}
-		assert.Equal(t, env.getcwd(), tc.Expected)
+		assert.Equal(t, env.pwd(), tc.Expected)
 	}
 }
diff --git a/src/segment_angular_test.go b/src/segment_angular_test.go
index 087a32b7..0e37d8a7 100644
--- a/src/segment_angular_test.go
+++ b/src/segment_angular_test.go
@@ -24,7 +24,7 @@ func TestAngularCliVersionDisplayed(t *testing.T) {
 
 		var env = new(MockedEnvironment)
 		// mock  getVersion methods
-		env.On("getcwd").Return("/usr/home/dev/my-app")
+		env.On("pwd").Return("/usr/home/dev/my-app")
 		env.On("homeDir").Return("/usr/home")
 		env.On("hasFiles", params.extension).Return(true)
 		env.On("hasFilesInDir", "/usr/home/dev/my-app/node_modules/@angular/core", "package.json").Return(true)
diff --git a/src/segment_deprecated_test.go b/src/segment_deprecated_test.go
index 8c5e5a68..3475b8e3 100644
--- a/src/segment_deprecated_test.go
+++ b/src/segment_deprecated_test.go
@@ -755,7 +755,7 @@ func TestPythonVirtualEnv(t *testing.T) {
 		env.On("getenv", "CONDA_DEFAULT_ENV").Return(tc.CondaDefaultEnvName)
 		env.On("getenv", "PYENV_VERSION").Return(tc.PyEnvName)
 		env.On("getPathSeperator").Return("")
-		env.On("getcwd").Return("/usr/home/project")
+		env.On("pwd").Return("/usr/home/project")
 		env.On("homeDir").Return("/usr/home")
 		env.onTemplate()
 		props := properties{
diff --git a/src/segment_dotnet_test.go b/src/segment_dotnet_test.go
index 003edf43..c0a67acc 100644
--- a/src/segment_dotnet_test.go
+++ b/src/segment_dotnet_test.go
@@ -26,7 +26,7 @@ func bootStrapDotnetTest(args *dotnetArgs) *dotnet {
 
 	env.On("hasFiles", "*.cs").Return(true)
 	env.On("getPathSeperator").Return("")
-	env.On("getcwd").Return("/usr/home/project")
+	env.On("pwd").Return("/usr/home/project")
 	env.On("homeDir").Return("/usr/home")
 	env.onTemplate()
 	props := properties{
diff --git a/src/segment_git_test.go b/src/segment_git_test.go
index 532dbeb8..2af2bb0c 100644
--- a/src/segment_git_test.go
+++ b/src/segment_git_test.go
@@ -590,7 +590,7 @@ func TestGetGitCommand(t *testing.T) {
 		env := new(MockedEnvironment)
 		env.On("isWsl").Return(tc.IsWSL)
 		env.On("getRuntimeGOOS").Return(tc.GOOS)
-		env.On("getcwd").Return(tc.CWD)
+		env.On("pwd").Return(tc.CWD)
 		wslUname := "5.10.60.1-microsoft-standard-WSL2"
 		if tc.IsWSL1 {
 			wslUname = "4.4.0-19041-Microsoft"
diff --git a/src/segment_golang_test.go b/src/segment_golang_test.go
index c87f6e6f..61e914f6 100644
--- a/src/segment_golang_test.go
+++ b/src/segment_golang_test.go
@@ -21,7 +21,7 @@ func getMockedLanguageEnv(params *mockedLanguageParams) (*MockedEnvironment, pro
 	env.On("hasCommand", params.cmd).Return(true)
 	env.On("runCommand", params.cmd, []string{params.versionParam}).Return(params.versionOutput, nil)
 	env.On("hasFiles", params.extension).Return(true)
-	env.On("getcwd").Return("/usr/home/project")
+	env.On("pwd").Return("/usr/home/project")
 	env.On("homeDir").Return("/usr/home")
 	env.onTemplate()
 	props := properties{
diff --git a/src/segment_java_test.go b/src/segment_java_test.go
index 645fea0e..6c3a10ec 100644
--- a/src/segment_java_test.go
+++ b/src/segment_java_test.go
@@ -57,7 +57,7 @@ func TestJava(t *testing.T) {
 		env.On("hasCommand", "java").Return(true)
 		env.On("runCommand", "java", []string{"-Xinternalversion"}).Return(tc.Version, nil)
 		env.On("hasFiles", "pom.xml").Return(true)
-		env.On("getcwd").Return("/usr/home/project")
+		env.On("pwd").Return("/usr/home/project")
 		env.On("homeDir").Return("/usr/home")
 		if tc.JavaHomeEnabled {
 			env.On("getenv", "JAVA_HOME").Return("/usr/java")
diff --git a/src/segment_language_test.go b/src/segment_language_test.go
index e75e31b1..fb24fb22 100644
--- a/src/segment_language_test.go
+++ b/src/segment_language_test.go
@@ -48,7 +48,7 @@ func bootStrapLanguageTest(args *languageArgs) *language {
 	if args.inHome {
 		cwd = home
 	}
-	env.On("getcwd").Return(cwd)
+	env.On("pwd").Return(cwd)
 	env.On("homeDir").Return(home)
 	env.onTemplate()
 	if args.properties == nil {
diff --git a/src/segment_path_test.go b/src/segment_path_test.go
index 7ce962d6..6582adf3 100644
--- a/src/segment_path_test.go
+++ b/src/segment_path_test.go
@@ -19,7 +19,7 @@ func (env *MockedEnvironment) getenv(key string) string {
 	return args.String(0)
 }
 
-func (env *MockedEnvironment) getcwd() string {
+func (env *MockedEnvironment) pwd() string {
 	args := env.Called()
 	return args.String(0)
 }
@@ -274,7 +274,7 @@ func TestRootLocationHome(t *testing.T) {
 	for _, tc := range cases {
 		env := new(MockedEnvironment)
 		env.On("homeDir").Return(tc.HomePath)
-		env.On("getcwd").Return(tc.Pwd)
+		env.On("pwd").Return(tc.Pwd)
 		args := &args{
 			PSWD: &tc.Pswd,
 		}
@@ -426,7 +426,7 @@ func TestAgnosterPathStyles(t *testing.T) {
 		env := new(MockedEnvironment)
 		env.On("getPathSeperator").Return(tc.PathSeperator)
 		env.On("homeDir").Return(tc.HomePath)
-		env.On("getcwd").Return(tc.Pwd)
+		env.On("pwd").Return(tc.Pwd)
 		env.On("getRuntimeGOOS").Return(tc.GOOS)
 		env.On("stackCount").Return(0)
 		args := &args{
@@ -547,7 +547,7 @@ func TestGetFullPath(t *testing.T) {
 		}
 		env.On("getPathSeperator").Return(tc.PathSeparator)
 		env.On("homeDir").Return("/usr/home")
-		env.On("getcwd").Return(tc.Pwd)
+		env.On("pwd").Return(tc.Pwd)
 		env.On("getRuntimeGOOS").Return(tc.GOOS)
 		env.On("stackCount").Return(tc.StackCount)
 		args := &args{
@@ -598,7 +598,7 @@ func TestGetFullPathCustomMappedLocations(t *testing.T) {
 		env := new(MockedEnvironment)
 		env.On("getPathSeperator").Return("/")
 		env.On("homeDir").Return("/usr/home")
-		env.On("getcwd").Return(tc.Pwd)
+		env.On("pwd").Return(tc.Pwd)
 		env.On("getRuntimeGOOS").Return("")
 		args := &args{
 			PSWD: &tc.Pwd,
@@ -649,7 +649,7 @@ func TestGetFolderPathCustomMappedLocations(t *testing.T) {
 	env := new(MockedEnvironment)
 	env.On("getPathSeperator").Return("/")
 	env.On("homeDir").Return("/usr/home")
-	env.On("getcwd").Return(pwd)
+	env.On("pwd").Return(pwd)
 	env.On("getRuntimeGOOS").Return("")
 	args := &args{
 		PSWD: &pwd,
@@ -696,7 +696,7 @@ func TestAgnosterPath(t *testing.T) { // nolint:dupl
 		env := new(MockedEnvironment)
 		env.On("homeDir").Return(tc.Home)
 		env.On("getPathSeperator").Return(tc.PathSeparator)
-		env.On("getcwd").Return(tc.PWD)
+		env.On("pwd").Return(tc.PWD)
 		env.On("getRuntimeGOOS").Return("")
 		args := &args{
 			PSWD: &tc.PWD,
@@ -744,7 +744,7 @@ func TestAgnosterLeftPath(t *testing.T) { // nolint:dupl
 		env := new(MockedEnvironment)
 		env.On("homeDir").Return(tc.Home)
 		env.On("getPathSeperator").Return(tc.PathSeparator)
-		env.On("getcwd").Return(tc.PWD)
+		env.On("pwd").Return(tc.PWD)
 		env.On("getRuntimeGOOS").Return("")
 		args := &args{
 			PSWD: &tc.PWD,
@@ -792,7 +792,7 @@ func TestGetPwd(t *testing.T) {
 		env := new(MockedEnvironment)
 		env.On("getPathSeperator").Return("/")
 		env.On("homeDir").Return("/usr/home")
-		env.On("getcwd").Return(tc.Pwd)
+		env.On("pwd").Return(tc.Pwd)
 		env.On("getRuntimeGOOS").Return("")
 		args := &args{
 			PSWD: &tc.Pswd,
diff --git a/src/segment_python_test.go b/src/segment_python_test.go
index 2f245efb..c88f338f 100644
--- a/src/segment_python_test.go
+++ b/src/segment_python_test.go
@@ -50,7 +50,7 @@ func TestPythonTemplate(t *testing.T) {
 		env.On("getenv", "CONDA_DEFAULT_ENV").Return(tc.VirtualEnvName)
 		env.On("getenv", "PYENV_VERSION").Return(tc.VirtualEnvName)
 		env.On("getPathSeperator").Return("")
-		env.On("getcwd").Return("/usr/home/project")
+		env.On("pwd").Return("/usr/home/project")
 		env.On("homeDir").Return("/usr/home")
 		env.onTemplate()
 		props := properties{
diff --git a/src/segment_ruby_test.go b/src/segment_ruby_test.go
index 37cdd3d3..2664558f 100644
--- a/src/segment_ruby_test.go
+++ b/src/segment_ruby_test.go
@@ -96,7 +96,7 @@ func TestRuby(t *testing.T) {
 		env.On("hasFiles", "*.rb").Return(tc.HasRubyFiles)
 		env.On("hasFiles", "Rakefile").Return(tc.HasRakeFile)
 		env.On("hasFiles", "Gemfile").Return(tc.HasGemFile)
-		env.On("getcwd").Return("/usr/home/project")
+		env.On("pwd").Return("/usr/home/project")
 		env.On("homeDir").Return("/usr/home")
 		env.onTemplate()
 		props := properties{
diff --git a/src/segment_terraform_test.go b/src/segment_terraform_test.go
index 23768174..c3e3977c 100644
--- a/src/segment_terraform_test.go
+++ b/src/segment_terraform_test.go
@@ -16,7 +16,7 @@ func bootStrapTerraformTest(args *terraformArgs) *terraform {
 	env := new(MockedEnvironment)
 	env.On("hasCommand", "terraform").Return(args.hasTfCommand)
 	env.On("hasFolder", "/.terraform").Return(args.hasTfFolder)
-	env.On("getcwd").Return("")
+	env.On("pwd").Return("")
 	env.On("runCommand", "terraform", []string{"workspace", "show"}).Return(args.workspaceName, nil)
 	env.onTemplate()
 	k := &terraform{
diff --git a/src/segment_test.go b/src/segment_test.go
index 025011e5..57bfa989 100644
--- a/src/segment_test.go
+++ b/src/segment_test.go
@@ -82,7 +82,7 @@ func TestShouldIncludeFolder(t *testing.T) {
 		env := new(MockedEnvironment)
 		env.On("getRuntimeGOOS").Return(linuxPlatform)
 		env.On("homeDir").Return("")
-		env.On("getcwd").Return(cwd)
+		env.On("pwd").Return(cwd)
 		segment := &Segment{
 			Properties: properties{
 				IncludeFolders: tc.IncludeFolders,
@@ -99,7 +99,7 @@ func TestShouldIncludeFolderRegexInverted(t *testing.T) {
 	env := new(MockedEnvironment)
 	env.On("getRuntimeGOOS").Return(linuxPlatform)
 	env.On("homeDir").Return("")
-	env.On("getcwd").Return(cwd)
+	env.On("pwd").Return(cwd)
 	segment := &Segment{
 		Properties: properties{
 			ExcludeFolders: []string{"(?!Projects[\\/]).*"},
@@ -120,7 +120,7 @@ func TestShouldIncludeFolderRegexInvertedNonEscaped(t *testing.T) {
 	env := new(MockedEnvironment)
 	env.On("getRuntimeGOOS").Return(linuxPlatform)
 	env.On("homeDir").Return("")
-	env.On("getcwd").Return(cwd)
+	env.On("pwd").Return(cwd)
 	segment := &Segment{
 		Properties: properties{
 			ExcludeFolders: []string{"(?!Projects/).*"},