forked from getantibody/antibody
/
git_bundle.go
48 lines (41 loc) · 1008 Bytes
/
git_bundle.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
package antibody
import (
"os"
"os/exec"
"path/filepath"
"strings"
)
func (b gitBundle) Download() error {
if _, err := os.Stat(b.folder); os.IsNotExist(err) {
clone := exec.Command("git", "clone", "--depth", "1", b.url, b.folder)
return clone.Run()
}
return nil
}
func (b gitBundle) Update() error {
pull := exec.Command("git", "-C", b.folder, "pull", "origin", "master")
return pull.Run()
}
func (b gitBundle) Folder() string {
return b.folder
}
func (b gitBundle) Sourceables() []string {
globs := []string{"*.plugin.zsh", "*.zsh", "*.sh"}
for _, glob := range globs {
files, _ := filepath.Glob(filepath.Join(b.Folder(), glob))
if files != nil {
return files
}
}
return nil
}
type gitBundle struct {
url, folder string
}
// NewGitBundle creates a new Bundle using Github as its source.
func NewGitBundle(bundle, home string) Bundle {
return gitBundle{
url: "https://github.com/" + bundle,
folder: filepath.Join(home, strings.Replace(bundle, "/", "-", -1)),
}
}