diff --git a/Makefile b/Makefile index 1bc30e9..2b86940 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,7 @@ vet: go vet ./... watch: build + -./vmux stop 2>/dev/null watch --color -n2 ./vmux list clean: diff --git a/daemon.go b/daemon.go index c799b25..4dc8415 100644 --- a/daemon.go +++ b/daemon.go @@ -8,6 +8,8 @@ import ( "net/http" "os" "path/filepath" + "sort" + "strconv" "sync" "time" ) @@ -60,7 +62,7 @@ func (r *SessionRegistry) Update(info SessionInfo) { existing.PrevState = info.State } -// List returns a snapshot of all tracked sessions. +// List returns a snapshot of all tracked sessions, sorted by workspace number. func (r *SessionRegistry) List() []SessionInfo { r.mu.RLock() defer r.mu.RUnlock() @@ -69,6 +71,11 @@ func (r *SessionRegistry) List() []SessionInfo { for _, ts := range r.sessions { result = append(result, ts.Info) } + sort.Slice(result, func(i, j int) bool { + wi, _ := strconv.Atoi(result[i].Workspace) + wj, _ := strconv.Atoi(result[j].Workspace) + return wi < wj + }) return result }