Skip to content

Commit 99de1b0

Browse files
committed
fix: use last attached time to score tmux session
Relying on the sorting of the tmux session list to generate a score was not robust. To just attach the unix timestamp of the LastAttached date is robust and more elegant.
1 parent e5d9fff commit 99de1b0

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

lister/list.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ var srcStrategies = map[string]srcStrategy{
2929
"zoxide": listZoxide,
3030
}
3131

32-
const (
33-
srcOffset = 1000000
34-
srcFactor = 10000
35-
)
32+
const zoxideFactor = 100
3633

3734
func (l *RealLister) List(opts ListOptions) (model.SeshSessions, error) {
3835
allSessions := sessionFromSources(opts, l)
@@ -56,9 +53,7 @@ func sessionFromSources(opts ListOptions, l *RealLister) []model.SeshSession {
5653

5754
return lo.Map(lo.Values(sessions.Directory), func(session model.SeshSession, j int) model.SeshSession {
5855
if session.Src != "zoxide" {
59-
srcDownrank := float64(i) * srcFactor
60-
sessionDownrank := float64(j)
61-
session.Score = session.Score + srcOffset - srcDownrank - sessionDownrank
56+
session.Score = session.Score * zoxideFactor
6257
}
6358
return session
6459
})

lister/tmux.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func listTmux(l *RealLister) (model.SeshSessions, error) {
2626
Name: session.Name,
2727
Path: session.Path,
2828
Attached: session.Attached,
29+
Score: float64(session.LastAttached.Unix()),
2930
Windows: session.Windows,
3031
}
3132
}
@@ -76,6 +77,7 @@ func GetAttachedTmuxSession(l *RealLister) (model.SeshSession, bool) {
7677
Name: session.Name,
7778
Path: session.Path,
7879
Attached: session.Attached,
80+
Score: float64(session.LastAttached.Unix()),
7981
Windows: session.Windows,
8082
}, true
8183
}

0 commit comments

Comments
 (0)