diff --git a/lister/list.go b/lister/list.go index d5aedbf..5646217 100644 --- a/lister/list.go +++ b/lister/list.go @@ -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) ) @@ -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, diff --git a/seshcli/list.go b/seshcli/list.go index 20d5568..d9836a2 100644 --- a/seshcli/list.go +++ b/seshcli/list.go @@ -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)