-
-
Notifications
You must be signed in to change notification settings - Fork 302
/
generate.go
85 lines (74 loc) · 1.7 KB
/
generate.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
//go:generate go run generate.go
// we want to re-use the existing Go syntax,
// but AFAIK, there's no way to do that if we disable the Go package...
// and we/I don't want to enable it because it includes a lot annoying snippets, etc.
package main
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
"os"
"os/exec"
"path/filepath"
)
type dlFile struct {
name string
url string
dirs []string
filt func(s []byte) []byte
}
func main() {
urls := []dlFile{
{
name: "Comments.tmPreferences",
url: "https://raw.githubusercontent.com/sublimehq/Packages/master/Go/Comments.tmPreferences",
dirs: []string{"../..", "."},
},
{
name: "Indentation Rules.tmPreferences",
url: "https://raw.githubusercontent.com/sublimehq/Packages/master/Go/Indentation%20Rules.tmPreferences",
dirs: []string{"../..", "."},
},
{
name: "Go.sublime-syntax",
url: "https://raw.githubusercontent.com/sublimehq/Packages/master/Go/Go.sublime-syntax",
dirs: []string{"."},
filt: func(s []byte) []byte {
return bytes.Replace(s, []byte("name: Go"), []byte("name: 'GoSublime: Go (Copy)'"), -1)
},
},
}
for _, f := range urls {
dl(f)
}
cmd := exec.Command("git", "status", "--short")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Run()
}
func dl(f dlFile) {
fmt.Printf("Sync %s: ", f.name)
resp, err := http.Get(f.url)
if err != nil {
fmt.Println(err)
return
}
defer resp.Body.Close()
content, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println(err)
return
}
if f.filt != nil {
content = f.filt(content)
}
for _, dir := range f.dirs {
ioutil.WriteFile(filepath.Join(dir, f.name), content, 0644)
if err != nil {
fmt.Println(err)
return
}
}
fmt.Println("ok")
}