Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions cmd/lsdesktop/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,21 @@ import (
"io/fs"
"os"
"path/filepath"
"slices"
"strings"

"github.com/FLchs/lsdesktop/internal/desktop"
"github.com/FLchs/lsdesktop/internal/history"
)

func currentDesktops() []string {
val := os.Getenv("XDG_CURRENT_DESKTOP")
if val == "" {
return nil
}
return strings.Split(val, ":")
}

func appDirs() []string {
dirs := make([]string, 0, 4)

Expand Down Expand Up @@ -38,6 +47,8 @@ func appDirs() []string {
}

func main() {
desktops := currentDesktops()

hist, err := history.ReadHistory()
if err != nil {
fmt.Fprintf(os.Stderr, "Error: read history: %v\n", err)
Expand Down Expand Up @@ -76,6 +87,17 @@ func main() {
return nil
}

if len(entry.OnlyShowIn) > 0 && !slices.ContainsFunc(entry.OnlyShowIn, func(s string) bool {
return slices.Contains(desktops, s)
}) {
return nil
}
if len(entry.NotShowIn) > 0 && slices.ContainsFunc(entry.NotShowIn, func(s string) bool {
return slices.Contains(desktops, s)
}) {
return nil
}

if _, ok := seen[entry.Name]; ok {
return nil
}
Expand Down
21 changes: 19 additions & 2 deletions internal/desktop/desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
func ParseEntry(data string) (DesktopEntry, bool) {
var name string
visible := true
var entry DesktopEntry

for line := range strings.SplitSeq(data, "\n") {
line = strings.TrimSpace(line)
Expand All @@ -30,6 +31,20 @@ func ParseEntry(data string) (DesktopEntry, bool) {
visible = false
}
}
if v, ok := strings.CutPrefix(line, "OnlyShowIn="); ok {
for s := range strings.SplitSeq(v, ";") {
if s != "" {
entry.OnlyShowIn = append(entry.OnlyShowIn, s)
}
}
}
if v, ok := strings.CutPrefix(line, "NotShowIn="); ok {
for s := range strings.SplitSeq(v, ";") {
if s != "" {
entry.NotShowIn = append(entry.NotShowIn, s)
}
}
}
}

return DesktopEntry{Name: name}, visible && name != ""
Expand All @@ -49,8 +64,10 @@ func CleanExec(execLine string) string {
}

type DesktopEntry struct {
Name string
Path string
Name string
Path string
OnlyShowIn []string
NotShowIn []string
}

func EntryString(name, path string) string {
Expand Down
Loading