Repository: JanDeDobbeleer/oh-my-posh
Pull request #1791 (2022-02-20 15:00:19)

fix(migrate): correctly migrate exit segment
### 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

<!--TemplateBody-->

<!---

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/engine/init.go b/src/engine/init.go
index cc4f4c8a..dda0668b 100644
--- a/src/engine/init.go
+++ b/src/engine/init.go
@@ -48,7 +48,10 @@ func getExecutablePath(shell string) (string, error) {
 	executable = strings.ReplaceAll(executable, "\\", "/")
 	switch shell {
 	case bash, zsh:
-		return strings.ReplaceAll(executable, " ", "\\ "), nil
+		executable = strings.ReplaceAll(executable, " ", "\\ ")
+		executable = strings.ReplaceAll(executable, "(", "\\(")
+		executable = strings.ReplaceAll(executable, ")", "\\)")
+		return executable, nil
 	}
 	return executable, nil
 }
diff --git a/src/engine/migrate.go b/src/engine/migrate.go
index d76dd017..77071286 100644
--- a/src/engine/migrate.go
+++ b/src/engine/migrate.go
@@ -134,16 +134,16 @@ func (segment *Segment) migrationOne(env environment.Environment) {
 			template = strings.ReplaceAll(template, ".Text", ".Meaning")
 			segment.Properties[properties.SegmentTemplate] = template
 		}
+		displayExitCode := properties.Property("display_exit_code")
+		if !segment.Properties.GetBool(displayExitCode, true) {
+			delete(segment.Properties, displayExitCode)
+			template = strings.ReplaceAll(template, " {{ .Meaning }}", "")
+		}
 		alwaysNumeric := properties.Property("always_numeric")
 		if segment.Properties.GetBool(alwaysNumeric, false) {
 			delete(segment.Properties, alwaysNumeric)
 			template = strings.ReplaceAll(template, ".Meaning", ".Code")
 		}
-		displayExitCode := properties.Property("display_exit_code")
-		if !segment.Properties.GetBool(displayExitCode, true) {
-			delete(segment.Properties, displayExitCode)
-			template = "  "
-		}
 		segment.Properties[properties.SegmentTemplate] = template
 		segment.migrateTemplate()
 		segment.migrateIconOverride("success_icon", "\uf42e")


Test patch:
diff --git a/src/engine/migrate_test.go b/src/engine/migrate_test.go
index 6bc2ea01..283c8ba6 100644
--- a/src/engine/migrate_test.go
+++ b/src/engine/migrate_test.go
@@ -221,7 +221,7 @@ func TestSegmentTemplateMigration(t *testing.T) {
 		},
 		{
 			Case:     "EXIT - No exit code",
-			Expected: "  ",
+			Expected: " {{ if gt .Code 0 }}FAIL{{ else }}SUCCESS{{ end }} ",
 			Type:     EXIT,
 			Props: properties.Map{
 				"display_exit_code": false,
@@ -229,6 +229,19 @@ func TestSegmentTemplateMigration(t *testing.T) {
 				"error_icon":        "FAIL",
 			},
 		},
+		{
+			Case:     "EXIT - No spaces",
+			Expected: "{{ if gt .Code 0 }}💩{{ else }}🌵{{ end }}",
+			Type:     EXIT,
+			Props: properties.Map{
+				"prefix":            "",
+				"postfix":           "",
+				"display_exit_code": false,
+				"always_enabled":    true,
+				"success_icon":      "🌵",
+				"error_icon":        "💩",
+			},
+		},
 		{
 			Case:     "EXIT - Always numeric",
 			Expected: " {{ if gt .Code 0 }}FAIL {{ .Code }}{{ else }}SUCCESS{{ end }} ",