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

fix: list output with --hide-attached flag #161

Closed
wants to merge 4 commits into from
Closed
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
11 changes: 11 additions & 0 deletions lister/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package lister

import (
"fmt"
"strings"

"github.com/joshmedeski/sesh/model"
)
Expand All @@ -11,6 +12,8 @@ func configKey(name string) string {
}

func listConfig(l *RealLister) (model.SeshSessions, error) {
activeSessions, _ := listTmux(l)

orderedIndex := make([]string, 0)
directory := make(model.SeshSessionMap)
for _, session := range l.config.SessionConfigs {
Expand All @@ -21,8 +24,16 @@ func listConfig(l *RealLister) (model.SeshSessions, error) {
if err != nil {
return model.SeshSessions{}, fmt.Errorf("couldn't expand home: %q", err)
}
// check if session is attached
isAttached := 0
tmuxKey := strings.Replace(key, "config:", "tmux:", 1)
tmuxSession := activeSessions.Directory[tmuxKey]
if tmuxSession != (model.SeshSession{}) {
isAttached = tmuxSession.Attached
}
directory[key] = model.SeshSession{
Src: "config",
Attached: isAttached,
Name: session.Name,
Path: path,
StartupCommand: session.StartupCommand,
Expand Down
12 changes: 11 additions & 1 deletion lister/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,20 @@ func (l *RealLister) List(opts ListOptions) (model.SeshSessions, error) {
if err != nil {
return model.SeshSessions{}, err
}
fullOrderedIndex = append(fullOrderedIndex, sessions.OrderedIndex...)
filteredIndex := []string{}
for _, i := range sessions.OrderedIndex {
if opts.HideAttached && sessions.Directory[i].Attached == 1 {
// TODO: remove the item from the fullOrderedIndex
continue
}
filteredIndex = append(filteredIndex, i)
fullDirectory[i] = sessions.Directory[i]
}
if opts.HideAttached {
fullOrderedIndex = append(fullOrderedIndex, filteredIndex...)
} else {
fullOrderedIndex = append(fullOrderedIndex, sessions.OrderedIndex...)
}
}

return model.SeshSessions{
Expand Down