Skip to content

Commit

Permalink
feat: detect sln and sln files as project files
Browse files Browse the repository at this point in the history
  • Loading branch information
paulomorgado authored and JanDeDobbeleer committed Nov 1, 2023
1 parent 092a0f9 commit e37ad13
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ require (
github.com/mattn/go-runewidth v0.0.15
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
golang.org/x/mod v0.13.0
gopkg.in/yaml.v3 v3.0.1
)
Expand Down Expand Up @@ -89,7 +90,6 @@ require (
github.com/shopspring/decimal v1.3.1 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
github.com/zclconf/go-cty v1.13.1 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/sync v0.4.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
Expand Down
11 changes: 8 additions & 3 deletions src/segments/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/jandedobbeleer/oh-my-posh/src/platform"
"github.com/jandedobbeleer/oh-my-posh/src/properties"
"github.com/jandedobbeleer/oh-my-posh/src/regex"
"golang.org/x/exp/slices"

"github.com/BurntSushi/toml"
)
Expand Down Expand Up @@ -110,7 +111,7 @@ func (n *Project) Init(props properties.Properties, env platform.Environment) {
},
{
Name: "dotnet",
Files: []string{"*.vbproj", "*.fsproj", "*.csproj"},
Files: []string{"*.sln", "*.slnf", "*.vbproj", "*.fsproj", "*.csproj"},
Fetcher: n.getDotnetProject,
},
{
Expand Down Expand Up @@ -205,18 +206,22 @@ func (n *Project) getNuSpecPackage(_ ProjectItem) *ProjectData {
}

func (n *Project) getDotnetProject(_ ProjectItem) *ProjectData {
files := n.env.LsDir(n.env.Pwd())
var name string
var content string

extensions := []string{".sln", ".slnf", ".csproj", ".fsproj", ".vbproj"}
files := n.env.LsDir(n.env.Pwd())

// get the first match only
for _, file := range files {
extension := filepath.Ext(file.Name())
if extension == ".csproj" || extension == ".fsproj" || extension == ".vbproj" {
if slices.Contains(extensions, extension) {
name = strings.TrimSuffix(file.Name(), filepath.Ext(file.Name()))
content = n.env.FileContent(file.Name())
break
}
}

// the name of the parameter may differ depending on the version,
// so instead of xml.Unmarshal() we use regex:
tag := "(?P<TAG><.*TargetFramework.*>(?P<TFM>.*)</.*TargetFramework.*>)"
Expand Down
2 changes: 1 addition & 1 deletion website/docs/segments/project.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Supports:
- Poetry project (`pyproject.toml`)
- 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)
- .NET project (`*.sln`, `*.slnf`, `*.csproj`, `*.vbproj` or `*.fsproj`, first file match info is displayed)
- Julia project (`JuliaProject.toml`, `Project.toml`)
- PowerShell project (`*.psd1`, first file match info is displayed)

Expand Down

0 comments on commit e37ad13

Please sign in to comment.