🏗️ add/use new ListSessions

This commit is contained in:
James Walker 2021-12-01 22:14:34 -05:00
parent 45e1ab830f
commit 1ff2a54582
Signed by: walkah
GPG Key ID: 3C127179D6086E93
2 changed files with 19 additions and 7 deletions

View File

@ -8,7 +8,6 @@ import (
"os/exec"
"path"
"path/filepath"
"regexp"
"strings"
"syscall"
@ -206,11 +205,12 @@ func getConfigFilePath(name string) string {
func sessionExists(name string) bool {
t := Tmux{}
result, err := t.Exec("ls")
if err != nil {
return false
}
re := regexp.MustCompile(fmt.Sprintf("^%s:", name))
return re.MatchString(string(result))
sessions := t.ListSessions()
for _, s := range sessions {
if s == name {
return true
}
}
return false
}

View File

@ -42,6 +42,18 @@ func (t *Tmux) Attach(name string) {
}
}
func (t *Tmux) ListSessions() []string {
sessions := []string{}
result, err := t.Exec("ls", "-F", "#{session_name}")
if err != nil {
fmt.Println("Error:", err)
return sessions
}
lines := strings.Trim(string(result), "\n")
return strings.Split(lines, "\n")
}
func (t *Tmux) getBinary() string {
if t.BinPath != "" {
return t.BinPath