Skip to content

Commit 7be8ff1

Browse files
authored
feat: hide current and sort by last attached (#30)
1 parent 9a621c5 commit 7be8ff1

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

tmux/list.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package tmux
22

33
import (
4+
"sort"
45
"strings"
56
"time"
67

@@ -119,7 +120,7 @@ func List() ([]*TmuxSession, error) {
119120
for _, line := range lines {
120121
fields := strings.Split(line, " ") // Strings split by single space
121122
if len(fields) == 21 {
122-
sessions = append(sessions, &TmuxSession{
123+
session := &TmuxSession{
123124
Activity: convert.StringToTime(fields[0]),
124125
Alerts: convert.StringToIntSlice(fields[1]),
125126
Attached: convert.StringToInt(fields[2]),
@@ -141,6 +142,12 @@ func List() ([]*TmuxSession, error) {
141142
Path: fields[18],
142143
Stack: convert.StringToIntSlice(fields[19]),
143144
Windows: convert.StringToInt(fields[20]),
145+
}
146+
if session.Attached != 1 {
147+
sessions = append(sessions, session)
148+
}
149+
sort.Slice(sessions, func(i, j int) bool {
150+
return sessions[j].LastAttached.Before(*sessions[i].LastAttached)
144151
})
145152
}
146153
}

0 commit comments

Comments
 (0)