Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove duplicates in final list #216

Merged
merged 3 commits into from
Jan 27, 2025
Merged
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
29 changes: 22 additions & 7 deletions lister/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import (

type (
ListOptions struct {
Config bool
HideAttached bool
Icons bool
Json bool
Tmux bool
Zoxide bool
Tmuxinator bool
Config bool
HideAttached bool
Icons bool
Json bool
Tmux bool
Zoxide bool
Tmuxinator bool
HideDuplicates bool
}
srcStrategy func(*RealLister) (model.SeshSessions, error)
)
Expand Down Expand Up @@ -51,6 +52,20 @@ func (l *RealLister) List(opts ListOptions) (model.SeshSessions, error) {
}
}

if opts.HideDuplicates {
directoryHash := make(map[string]int)
destIndex := 0
for _, index := range fullOrderedIndex {
directoryPath := fullDirectory[index].Path
if _, exists := directoryHash[directoryPath]; !exists {
fullOrderedIndex[destIndex] = index
directoryHash[directoryPath] = 1
destIndex = destIndex + 1
}
}
fullOrderedIndex = fullOrderedIndex[:destIndex]
}

return model.SeshSessions{
OrderedIndex: fullOrderedIndex,
Directory: fullDirectory,
Expand Down
20 changes: 13 additions & 7 deletions seshcli/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,22 @@ func List(icon icon.Icon, json json.Json, list lister.Lister) *cli.Command {
Aliases: []string{"T"},
Usage: "show tmuxinator configs",
},
&cli.BoolFlag{
Name: "hide-duplicates",
Aliases: []string{"d"},
Usage: "hide duplicate entries",
},
},
Action: func(cCtx *cli.Context) error {
sessions, err := list.List(lister.ListOptions{
Config: cCtx.Bool("config"),
HideAttached: cCtx.Bool("hide-attached"),
Icons: cCtx.Bool("icons"),
Json: cCtx.Bool("json"),
Tmux: cCtx.Bool("tmux"),
Zoxide: cCtx.Bool("zoxide"),
Tmuxinator: cCtx.Bool("tmuxinator"),
Config: cCtx.Bool("config"),
HideAttached: cCtx.Bool("hide-attached"),
Icons: cCtx.Bool("icons"),
Json: cCtx.Bool("json"),
Tmux: cCtx.Bool("tmux"),
Zoxide: cCtx.Bool("zoxide"),
Tmuxinator: cCtx.Bool("tmuxinator"),
HideDuplicates: cCtx.Bool("hide-duplicates"),
})
if err != nil {
return fmt.Errorf("couldn't list sessions: %q", err)
Expand Down
Loading