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

feat: implement --hide-attached option #185

Merged
merged 1 commit into from
Oct 7, 2024
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
10 changes: 10 additions & 0 deletions lister/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ 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 Down
19 changes: 19 additions & 0 deletions lister/tmux.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,22 @@ func (l *RealLister) GetLastTmuxSession() (model.SeshSession, bool) {
secondSessionIndex := sessions.OrderedIndex[1]
return sessions.Directory[secondSessionIndex], true
}

func GetAttachedTmuxSession(l *RealLister) (model.SeshSession, bool) {
tmuxSessions, err := l.tmux.ListSessions()
if err != nil {
return model.SeshSession{}, false
}
for _, session := range tmuxSessions {
if session.Attached != 0 {
return model.SeshSession{
Src: "tmux",
Name: session.Name,
Path: session.Path,
Attached: session.Attached,
Windows: session.Windows,
}, true
}
}
return model.SeshSession{}, false
}