-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopen.go
51 lines (44 loc) · 1.35 KB
/
open.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"fmt"
"os"
)
func openRepo(config Config, repoName string) {
log := NewLogUtil()
repoBasePath := config.ReposBasePath
var selectedRepo string
if repoName == "" {
selectedRepo = selectRepo(repoBasePath)
} else {
selectedRepo = repoName
}
sessionName := createSessionName(selectedRepo)
sessionPath := createSessionPath(repoBasePath, selectedRepo)
inTmux := os.Getenv("TMUX") != ""
if sessionExists(sessionName) {
if inTmux {
log.Positive(fmt.Sprintf("Switching to session: %s", sessionName))
if err := tmux("switch-client", "-t", sessionName); err != nil {
log.Negative("Error switching to tmux session:", err)
}
} else {
log.Positive(fmt.Sprintf("Attaching to session: %s", sessionName))
if err := tmux("attach-session", "-t", sessionName); err != nil {
log.Negative("Error attaching to tmux session:", err)
}
}
} else {
createSession(config, sessionName, sessionPath)
if inTmux {
log.Positive(fmt.Sprintf("Switching to session: %s", sessionName))
if err := tmux("switch-client", "-t", sessionName); err != nil {
log.Negative("Error switching to tmux session:", err)
}
} else {
log.Positive(fmt.Sprintf("Attaching to session: %s", sessionName))
if err := tmux("attach-session", "-t", sessionName); err != nil {
log.Negative("Error attaching to tmux session:", err)
}
}
}
}