Skip to content

Commit

Permalink
feat: add --hide-duplicates flag to list command (#216)
Browse files Browse the repository at this point in the history
Providing the flag removes duplicates based on the Path entries
  • Loading branch information
szinn authored Jan 27, 2025
1 parent 213388d commit a972607
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
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

0 comments on commit a972607

Please sign in to comment.