Repository: JanDeDobbeleer/oh-my-posh
Pull request #3217 (2022-12-17 19:10:43)

Add support for Julia projects
### Prerequisites

- [x] I have read and understood the [contributing guide][CONTRIBUTING.md]
- [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

I'm trying to add support for Julia project files (these are either `Project.toml` or much less commonly `JuliaProject.toml` files). This PR doesn't seem to work, but I'm not sure what else I would have to do?

I'll add tests and docs once the code is working.

JanDeDobbeleer: @davidanthoff I added the tests, and it does work on my end using the [docs config](https://ohmyposh.dev/docs/segments/project#sample-configuration).

<img width="1088" alt="image" src="https://user-images.githubusercontent.com/2492783/208264336-310fd23b-15be-4013-804f-0cc20c8561fa.png">
davidanthoff: Ah, cool! I might well have had a mistake in how I tested it, this is the first go programming I've ever done :)

I added a small doc update commit as well now.

And just to confirm one thing: this all works if a project file is missing a `version` element, right? That is valid in Julia, and from looking at the code and the test that seems to be the case, but then my go knowledge is kind of not there, so want to make sure I'm understanding this correctly.
JanDeDobbeleer: @davidanthoff yes!

Patch:
diff --git a/src/segments/project.go b/src/segments/project.go
index 19e40efc..1f57fb9e 100644
--- a/src/segments/project.go
+++ b/src/segments/project.go
@@ -117,6 +117,11 @@ func (n *Project) Init(props properties.Properties, env platform.Environment) {
 			Files:   []string{"*.vbproj", "*.fsproj", "*.csproj"},
 			Fetcher: n.getDotnetProject,
 		},
+		{
+			Name:    "julia",
+			Files:   []string{"JuliaProject.toml", "Project.toml"},
+			Fetcher: n.getProjectData,
+		},
 	}
 }
 
@@ -226,3 +231,16 @@ func (n *Project) getDotnetProject(item ProjectItem) *ProjectData {
 		Name:   name,
 	}
 }
+
+func (n *Project) getProjectData(item ProjectItem) *ProjectData {
+	content := n.env.FileContent(item.Files[0])
+
+	var data ProjectData
+	_, err := toml.Decode(content, &data)
+	if err != nil {
+		n.Error = err.Error()
+		return nil
+	}
+
+	return &data
+}
diff --git a/website/docs/segments/project.mdx b/website/docs/segments/project.mdx
index 4116a3d9..c777b8d6 100644
--- a/website/docs/segments/project.mdx
+++ b/website/docs/segments/project.mdx
@@ -16,6 +16,7 @@ Supports:
 - PHP project (`composer.json`)
 - Any nuspec based project (`*.nuspec`, first file match info is displayed)
 - .NET project (`*.csproj`, `*.vbproj` or `*.fsproj`, first file match info is displayed)
+- Julia project (`JuliaProject.toml`, `Project.toml`)
 
 ## Sample Configuration
 


Test patch:
diff --git a/src/segments/project_test.go b/src/segments/project_test.go
index 94fe4e6e..861064eb 100644
--- a/src/segments/project_test.go
+++ b/src/segments/project_test.go
@@ -186,6 +186,37 @@ func TestPackage(t *testing.T) {
 			File:            "Cargo.toml",
 			PackageContents: "[",
 		},
+		{
+			Case:            "Julia project",
+			ExpectedEnabled: true,
+			ExpectedString:  "\uf487 0.1.0 ProjectEuler",
+			Name:            "julia",
+			File:            "JuliaProject.toml",
+			PackageContents: "name = \"ProjectEuler\"\nversion = \"0.1.0\"",
+		},
+		{
+			Case:            "Julia project no name",
+			ExpectedEnabled: true,
+			ExpectedString:  "\uf487 0.1.0",
+			Name:            "julia",
+			File:            "JuliaProject.toml",
+			PackageContents: "version = \"0.1.0\"",
+		},
+		{
+			Case:            "Julia project no version",
+			ExpectedEnabled: true,
+			ExpectedString:  "ProjectEuler",
+			Name:            "julia",
+			File:            "JuliaProject.toml",
+			PackageContents: "name = \"ProjectEuler\"",
+		},
+		{
+			Case:            "Julia project invalid toml",
+			ExpectedString:  "toml: line 1: unexpected end of table name (table names cannot be empty)",
+			Name:            "julia",
+			File:            "JuliaProject.toml",
+			PackageContents: "[",
+		},
 	}
 
 	for _, tc := range cases {