forked from wricardo/gomux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd.go
131 lines (99 loc) · 3.08 KB
/
cmd.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package gomux
type killSession struct {
targetSession string
}
type newSession struct {
notAttachedToCurrentTerminal bool
sessionName string
windowName string
workingDir string
}
type newWindow struct {
targetWindow []string
windowName string
workingDir string
}
type renameWindow struct {
targetWindow []string
windowName string
}
type splitWindow struct {
horizontalSplit bool
verticalSplit bool
targetPane string
workingDir string
}
type selectWindow struct {
targetWindow string
}
// This will silently kill a given tmux session
func (session killSession) String() (killCommand []string) {
killCommand = append(killCommand, "kill-session", "-t", session.targetSession)
return killCommand
}
func (session newSession) String() (newSessionCommand []string) {
newSessionCommand = append(newSessionCommand, "new-session")
if session.notAttachedToCurrentTerminal == true {
newSessionCommand = append(newSessionCommand, "-d")
}
if session.sessionName != "" {
newSessionCommand = append(newSessionCommand, "-s", session.sessionName)
}
if session.windowName != "" {
newSessionCommand = append(newSessionCommand, "-n", session.windowName)
}
if session.workingDir != "" {
newSessionCommand = append(newSessionCommand, "-c", session.workingDir)
}
return newSessionCommand
}
func (window splitWindow) String() (splitWindowCommand []string) {
splitWindowCommand = append(splitWindowCommand, "split-window")
if window.horizontalSplit == true {
splitWindowCommand = append(splitWindowCommand, "-h")
}
if window.verticalSplit == true {
splitWindowCommand = append(splitWindowCommand, "-v")
}
if window.targetPane != "" {
splitWindowCommand = append(splitWindowCommand, "-t", window.targetPane)
}
if window.workingDir != "" {
splitWindowCommand = append(splitWindowCommand, "-c", window.workingDir)
}
return splitWindowCommand
}
func (window newWindow) String() (newWindowCommand []string) {
newWindowCommand = append(newWindowCommand, "new-window")
if len(window.targetWindow) != 0 {
for _, v := range window.targetWindow {
newWindowCommand = append(newWindowCommand, v)
}
}
if window.windowName != "" {
newWindowCommand = append(newWindowCommand, "-n", window.windowName)
}
if window.workingDir != "" {
newWindowCommand = append(newWindowCommand, "-c", window.workingDir)
}
return newWindowCommand
}
func (window renameWindow) String() (renameWindowCommand []string) {
renameWindowCommand = append(renameWindowCommand, "rename-window")
if len(window.targetWindow) != 0 {
for _, v := range window.targetWindow {
renameWindowCommand = append(renameWindowCommand, v)
}
}
if window.windowName != "" {
renameWindowCommand = append(renameWindowCommand, window.windowName)
}
return renameWindowCommand
}
func (window selectWindow) String() (selectWindowCommand []string) {
selectWindowCommand = append(selectWindowCommand, "select-window")
if window.targetWindow != "" {
selectWindowCommand = append(selectWindowCommand, "-t", window.targetWindow)
}
return selectWindowCommand
}