🏗️ add/use new ListSessions
This commit is contained in:
parent
45e1ab830f
commit
1ff2a54582
@ -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
|
||||
}
|
||||
|
12
tmux/tmux.go
12
tmux/tmux.go
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user