This repository was archived by the owner on Jan 17, 2021. It is now read-only.
File tree 2 files changed +41
-4
lines changed
2 files changed +41
-4
lines changed Original file line number Diff line number Diff line change @@ -50,3 +50,9 @@ This operation may take a while on a slow connections, but will be fast
50
50
on follow-up connections to the same server.
51
51
52
52
To disable this feature entirely, pass the ` --skipsync ` flag.
53
+
54
+ ### Sync-back
55
+
56
+ By default, extensions installed on the remote server won't be sync'd back
57
+ when the connection closes. To synchronize back to local when the connection ends,
58
+ pass the ` -b ` flag.
Original file line number Diff line number Diff line change @@ -9,9 +9,11 @@ import (
9
9
"net/http"
10
10
"os"
11
11
"os/exec"
12
+ "os/signal"
12
13
"path/filepath"
13
14
"runtime"
14
15
"strconv"
16
+ "sync"
15
17
"time"
16
18
17
19
"github.com/pkg/browser"
@@ -24,8 +26,12 @@ func init() {
24
26
}
25
27
26
28
func main () {
27
- skipSyncFlag := flag .Bool ("skipsync" , false , "skip syncing local settings and extensions to remote host" )
28
- sshFlags := flag .String ("ssh-flags" , "" , "custom SSH flags" )
29
+ var (
30
+ skipSyncFlag = flag .Bool ("skipsync" , false , "skip syncing local settings and extensions to remote host" )
31
+ sshFlags = flag .String ("ssh-flags" , "" , "custom SSH flags" )
32
+ syncBack = flag .Bool ("b" , false , "sync extensions back on SIGINT" )
33
+ )
34
+
29
35
flag .Usage = func () {
30
36
fmt .Printf (`Usage: [-skipsync] %v HOST [DIR] [SSH ARGS...]
31
37
@@ -131,8 +137,33 @@ chmod +x `+codeServerPath+`
131
137
break
132
138
}
133
139
134
- openBrowser (url )
135
- sshCmd .Wait ()
140
+ ctx , cancel := context .WithCancel ()
141
+ go func () {
142
+ defer cancel ()
143
+ openBrowser (url )
144
+ sshCmd .Wait ()
145
+ }()
146
+
147
+ c := make (chan os.Signal )
148
+ signal .Notify (c , os .Interrupt )
149
+
150
+ var shutdownWg sync.WaitGroup
151
+ shutdownWg .Add (1 )
152
+ go func () {
153
+ defer shutdownWg .Done ()
154
+
155
+ select {
156
+ case <- ctx .Done ():
157
+ case <- c :
158
+ }
159
+
160
+ if ! * syncBack {
161
+ flog .Info ("shutting down" )
162
+ return
163
+ }
164
+ }()
165
+
166
+ shutdownWg .Wait ()
136
167
}
137
168
138
169
func openBrowser (url string ) {
You can’t perform that action at this time.
0 commit comments