Skip to content
Merged
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
21 changes: 11 additions & 10 deletions lister/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package lister

import (
"github.com/joshmedeski/sesh/v2/model"
"slices"
)

type (
Expand Down Expand Up @@ -37,16 +38,6 @@ func (l *RealLister) List(opts ListOptions) (model.SeshSessions, error) {
if err != nil {
return model.SeshSessions{}, err
}
if opts.HideAttached {
attachedSession, _ := GetAttachedTmuxSession(l)
sessionsCopy := sessions.OrderedIndex
for i, ses := range sessionsCopy {
if attachedSession.Name == sessions.Directory[ses].Name {
sessions.OrderedIndex = append(sessions.OrderedIndex[:i],
sessions.OrderedIndex[i+1:]...)
}
}
}
fullOrderedIndex = append(fullOrderedIndex, sessions.OrderedIndex...)
for _, i := range sessions.OrderedIndex {
fullDirectory[i] = sessions.Directory[i]
Expand All @@ -71,6 +62,16 @@ func (l *RealLister) List(opts ListOptions) (model.SeshSessions, error) {
fullOrderedIndex = fullOrderedIndex[:destIndex]
}

if opts.HideAttached {
attachedSession, _ := GetAttachedTmuxSession(l)
for i, index := range fullOrderedIndex {
if fullDirectory[index].Name == attachedSession.Name {
fullOrderedIndex = slices.Delete(fullOrderedIndex, i, i+1)
break
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Does it seem right to break here? Is it possible to have two sessions with the same .Name?
  2. If it's not possible to have two sessions with the same .Name, isn't the active session always first in the list? So Couldn't I skip the iteration and just check fullDirectory[fullOrderedIndex[0]].Name against attachedSession.Name to save a bunch of CPU cycles?

}
}
}

return model.SeshSessions{
OrderedIndex: fullOrderedIndex,
Directory: fullDirectory,
Expand Down