Skip to content

Commit

Permalink
feat: hide current and sort by last attached (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshmedeski authored Jan 19, 2024
1 parent 9a621c5 commit 7be8ff1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tmux/list.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tmux

import (
"sort"
"strings"
"time"

Expand Down Expand Up @@ -119,7 +120,7 @@ func List() ([]*TmuxSession, error) {
for _, line := range lines {
fields := strings.Split(line, " ") // Strings split by single space
if len(fields) == 21 {
sessions = append(sessions, &TmuxSession{
session := &TmuxSession{
Activity: convert.StringToTime(fields[0]),
Alerts: convert.StringToIntSlice(fields[1]),
Attached: convert.StringToInt(fields[2]),
Expand All @@ -141,6 +142,12 @@ func List() ([]*TmuxSession, error) {
Path: fields[18],
Stack: convert.StringToIntSlice(fields[19]),
Windows: convert.StringToInt(fields[20]),
}
if session.Attached != 1 {
sessions = append(sessions, session)
}
sort.Slice(sessions, func(i, j int) bool {
return sessions[j].LastAttached.Before(*sessions[i].LastAttached)
})
}
}
Expand Down

0 comments on commit 7be8ff1

Please sign in to comment.