Skip to content
This repository was archived by the owner on Jan 17, 2021. It is now read-only.

Commit aa6ad45

Browse files
committed
Add flag to sync extensions back to local
Resolves #20
1 parent 3f4919f commit aa6ad45

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,9 @@ This operation may take a while on a slow connections, but will be fast
5050
on follow-up connections to the same server.
5151

5252
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.

main.go

+35-4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ import (
99
"net/http"
1010
"os"
1111
"os/exec"
12+
"os/signal"
1213
"path/filepath"
1314
"runtime"
1415
"strconv"
16+
"sync"
1517
"time"
1618

1719
"github.com/pkg/browser"
@@ -24,8 +26,12 @@ func init() {
2426
}
2527

2628
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+
2935
flag.Usage = func() {
3036
fmt.Printf(`Usage: [-skipsync] %v HOST [DIR] [SSH ARGS...]
3137
@@ -131,8 +137,33 @@ chmod +x `+codeServerPath+`
131137
break
132138
}
133139

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()
136167
}
137168

138169
func openBrowser(url string) {

0 commit comments

Comments
 (0)