@@ -64,6 +64,8 @@ func main() {
64
64
sshFlags = flag .String ("ssh-flags" , "" , "custom SSH flags" )
65
65
syncBack = flag .Bool ("b" , false , "sync extensions back on termination" )
66
66
printVersion = flag .Bool ("version" , false , "print version information and exit" )
67
+ port = flag .String ("port" , "" , "Start VS Code on the provided port. If one is not provided a random one is selected" )
68
+ noOpen = flag .Bool ("no-open" , false , "Start VS Code but don't open a Chrome app window" )
67
69
)
68
70
69
71
flag .Usage = func () {
@@ -107,14 +109,8 @@ Arguments:
107
109
108
110
const codeServerPath = "/tmp/codessh-code-server"
109
111
110
- downloadScript := `set -euxo pipefail || exit 1
112
+ dlScript := downloadScript ( codeServerPath )
111
113
112
- mkdir -p ~/.local/share/code-server
113
- cd ` + filepath .Dir (codeServerPath ) + `
114
- wget -N https://codesrv-ci.cdr.sh/latest-linux
115
- [ -f ` + codeServerPath + ` ] && rm ` + codeServerPath + `
116
- ln latest-linux ` + codeServerPath + `
117
- chmod +x ` + codeServerPath
118
114
// Downloads the latest code-server and allows it to be executed.
119
115
sshCmdStr := fmt .Sprintf ("ssh" +
120
116
" " + * sshFlags + " " +
@@ -123,7 +119,7 @@ chmod +x ` + codeServerPath
123
119
sshCmd := exec .Command ("sh" , "-c" , sshCmdStr )
124
120
sshCmd .Stdout = os .Stdout
125
121
sshCmd .Stderr = os .Stderr
126
- sshCmd .Stdin = strings .NewReader (downloadScript )
122
+ sshCmd .Stdin = strings .NewReader (dlScript )
127
123
err := sshCmd .Run ()
128
124
if err != nil {
129
125
flog .Fatal ("failed to update code-server: %v\n ---ssh cmd---\n %s\n ---download script---\n %s" , err ,
@@ -150,7 +146,11 @@ chmod +x ` + codeServerPath
150
146
}
151
147
152
148
flog .Info ("starting code-server..." )
153
- localPort , err := randomPort ()
149
+
150
+ localPort := * port
151
+ if localPort == "" {
152
+ localPort , err = randomPort ()
153
+ }
154
154
if err != nil {
155
155
flog .Fatal ("failed to find available port: %v" , err )
156
156
}
@@ -160,9 +160,7 @@ chmod +x ` + codeServerPath
160
160
)
161
161
162
162
// Starts code-server and forwards the remote port.
163
- sshCmd = exec .Command ("sh" , "-c" ,
164
- sshCmdStr ,
165
- )
163
+ sshCmd = exec .Command ("sh" , "-c" , sshCmdStr )
166
164
sshCmd .Stdin = os .Stdin
167
165
sshCmd .Stdout = os .Stdout
168
166
sshCmd .Stderr = os .Stderr
@@ -190,7 +188,10 @@ chmod +x ` + codeServerPath
190
188
}
191
189
192
190
ctx , cancel = context .WithCancel (context .Background ())
193
- openBrowser (url )
191
+
192
+ if ! * noOpen {
193
+ openBrowser (url )
194
+ }
194
195
195
196
go func () {
196
197
defer cancel ()
@@ -352,3 +353,22 @@ func rsync(src string, dest string, sshFlags string, excludePaths ...string) err
352
353
353
354
return nil
354
355
}
356
+
357
+ func downloadScript (codeServerPath string ) string {
358
+ return fmt .Sprintf (
359
+ `set -euxo pipefail || exit 1
360
+
361
+ mkdir -p ~/.local/share/code-server
362
+ cd %v
363
+ wget -N https://codesrv-ci.cdr.sh/latest-linux
364
+ [ -f %v ] && rm %v
365
+ ln latest-linux %v
366
+ chmod +x %v` ,
367
+ filepath .Dir (codeServerPath ),
368
+ codeServerPath ,
369
+ codeServerPath ,
370
+ codeServerPath ,
371
+ codeServerPath ,
372
+ )
373
+
374
+ }
0 commit comments