This repository has been archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
get-plugins.go
executable file
·121 lines (105 loc) · 2.57 KB
/
get-plugins.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
package main
import (
"context"
"log"
"os"
"os/exec"
"strings"
"sync"
"time"
)
func main() {
var wg sync.WaitGroup
wg.Add(1)
// assumes github.com
colors := []string{
"robertmeta/nofrils",
"romainl/Apprentice",
"romainl/Disciple",
"cormacrelf/vim-colors-github",
}
plugins := []string{
"airblade/vim-gitgutter",
"fatih/vim-go",
"hauleth/asyncdo.vim",
"joereynolds/vim-minisnip",
"kopischke/vim-fetch",
//"lifepillar/vim-mucomplete",
"ludovicchabant/vim-gutentags",
"machakann/vim-sandwich",
"Olical/vim-enmasse",
"prettier/vim-prettier",
"romainl/vim-qf",
"romainl/vim-qlist",
"scrooloose/nerdtree",
"t9md/vim-quickhl",
"tpope/vim-abolish",
"tpope/vim-commentary",
"tpope/vim-eunuch",
"tpope/vim-fugitive",
"tpope/vim-repeat",
"tpope/vim-rsi",
"tpope/vim-unimpaired",
//"tpope/vim-vinegar",
"w0rp/ale",
"wellle/tmux-complete.vim",
"wincent/terminus",
"xtal8/traces.vim",
}
clearPack()
for _, v := range plugins {
wg.Add(1)
go updatePlugin(&wg, "plugins", v)
}
for _, v := range colors {
wg.Add(1)
go updatePlugin(&wg, "colors", v)
}
wg.Done()
wg.Wait()
}
func clearPack() {
mustNotError(os.RemoveAll("pack/"), "on pack")
mustNotError(os.MkdirAll("pack/", 0777), "on mkdir2")
}
// TODO: use os.PathSeperator
func updatePlugin(wg *sync.WaitGroup, org, plugin string) {
fullURL := "https://github.com/" + plugin
localPath := "pack/" + org + "/start/" + strings.Replace(strings.Replace(strings.Replace(strings.ToLower(plugin), `/`, `-`, -1), `.vim`, `-vim`, 1), `_`, `-`, -1)
log.Println(localPath, "started")
mustNotError(os.MkdirAll(localPath, 0777), "on mkdir")
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
x, err := exec.CommandContext(ctx, "git", "clone", fullURL, localPath).CombinedOutput()
mustNotError(err, "on clone:"+string(x))
mustNotError(os.RemoveAll(localPath+"/.git"), "on removeall")
os.RemoveAll(localPath + "/.gitignore")
docsPath := localPath + "/doc"
docsExist, err := exists(docsPath)
mustNotError(err, "on exists")
if docsExist {
x, err := exec.CommandContext(ctx, "vim", "-c", "helptags "+docsPath+" | q").CombinedOutput()
if err != nil { // don't crash, just error
log.Println(string(x))
log.Println(err)
}
}
log.Println(localPath, "done")
wg.Done()
}
func mustNotError(err error, note string) {
if err != nil {
log.Println(note)
log.Fatal(err)
}
}
func exists(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil {
return true, nil
}
if os.IsNotExist(err) {
return false, nil
}
return true, err
}