Skip to content
This repository has been archived by the owner on May 27, 2022. It is now read-only.

fix: multiple oh-my-zsh plugins behavior #244

Merged
merged 9 commits into from
Jul 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 43 additions & 1 deletion antibodylib/antibody_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ func TestMultipleRepositories(t *testing.T) {
"zsh-users/zsh-completions",
"zsh-users/zsh-autosuggestions",
"",
"robbyrussell/oh-my-zsh folder:plugins/asdf",
"robbyrussell/oh-my-zsh folder:plugins/autoenv",
"# these should be at last!",
"sindresorhus/pure",
"zsh-users/zsh-syntax-highlighting",
Expand All @@ -77,7 +79,47 @@ func TestMultipleRepositories(t *testing.T) {
runtime.NumCPU(),
).Bundle()
assert.NoError(t, err)
assert.Len(t, strings.Split(sh, "\n"), 27)
assert.Len(t, strings.Split(sh, "\n"), 31)
}

// BenchmarkDownload-8 1 2907868713 ns/op 480296 B/op 2996 allocs/op v1
// BenchmarkDownload-8 1 2708120385 ns/op 475904 B/op 3052 allocs/op v2
func BenchmarkDownload(b *testing.B) {
var bundles = strings.Join([]string{
"robbyrussell/oh-my-zsh folder:plugins/aws",
"caarlos0/git-add-remote kind:path",
"caarlos0/jvm",
"caarlos0/ports kind:path",
"",
"# comment whatever",
"caarlos0/zsh-git-fetch-merge kind:path",
"robbyrussell/oh-my-zsh folder:plugins/battery",
"caarlos0/zsh-git-sync kind:path",
"caarlos0/zsh-mkc",
"caarlos0/zsh-open-pr kind:path",
"robbyrussell/oh-my-zsh folder:plugins/asdf",
"mafredri/zsh-async",
"rupa/z",
"Tarrasch/zsh-bd",
"",
"wbinglee/zsh-wakatime",
"zsh-users/zsh-completions",
"zsh-users/zsh-autosuggestions",
"robbyrussell/oh-my-zsh folder:plugins/autoenv",
"# these should be at last!",
"sindresorhus/pure",
"zsh-users/zsh-syntax-highlighting",
"zsh-users/zsh-history-substring-search",
}, "\n")
for i := 0; i < b.N; i++ {
home := home()
_, err := antibodylib.New(
home,
bytes.NewBufferString(bundles),
runtime.NumCPU(),
).Bundle()
assert.NoError(b, err)
}
}

func TestHome(t *testing.T) {
Expand Down
7 changes: 7 additions & 0 deletions project/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os/exec"
"path/filepath"
"strings"
"sync"

"github.com/getantibody/folder"
)
Expand Down Expand Up @@ -72,7 +73,13 @@ func NewGit(cwd, line string) Project {
}
}

var locks sync.Map

func (g gitProject) Download() error {
l, _ := locks.LoadOrStore(g.folder, &sync.Mutex{})
lock := l.(*sync.Mutex)
lock.Lock()
defer lock.Unlock()
if _, err := os.Stat(g.folder); os.IsNotExist(err) {
// #nosec
var cmd = exec.Command("git", "clone",
Expand Down
6 changes: 4 additions & 2 deletions project/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ func TestSubFolder(t *testing.T) {

func TestMultipleSubFolders(t *testing.T) {
home := home()
assert.NoError(t, project.NewGit(home, "robbyrussell/oh-my-zsh folder:plugins/aws").Download())
assert.NoError(t, project.NewGit(home, "robbyrussell/oh-my-zsh folder:plugins/battery").Download())
assert.NoError(t, project.NewGit(home, strings.Join([]string{
"robbyrussell/oh-my-zsh folder:plugins/aws",
"robbyrussell/oh-my-zsh folder:plugins/battery",
}, "\n")).Download())
}

func home() string {
Expand Down
13 changes: 13 additions & 0 deletions www/content/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,17 @@ Example:
```console
$ antibody bundle robbyrussell/oh-my-zsh folder:plugins/aws
source /Users/carlos/Library/Caches/antibody/https-COLON--SLASH--SLASH-github.com-SLASH-robbyrussell-SLASH-oh-my-zsh/plugins/aws/aws.plugin.zsh
fpath+=( /Users/carlos/Library/Caches/antibody/https-COLON--SLASH--SLASH-github.com-SLASH-robbyrussell-SLASH-oh-my-zsh/plugins/aws )
```

If you want multiple folders from the same plugin, you can just repeat the
plugin with a different `folder` option:

```console
$ antibody bundle "robbyrussell/oh-my-zsh folder:plugins/aws
robbyrussell/oh-my-zsh folder:plugins/asdf"
source /Users/carlos/Library/Caches/antibody/https-COLON--SLASH--SLASH-github.com-SLASH-robbyrussell-SLASH-oh-my-zsh/plugins/aws/aws.plugin.zsh
fpath+=( /Users/carlos/Library/Caches/antibody/https-COLON--SLASH--SLASH-github.com-SLASH-robbyrussell-SLASH-oh-my-zsh/plugins/aws )
source /Users/carlos/Library/Caches/antibody/https-COLON--SLASH--SLASH-github.com-SLASH-robbyrussell-SLASH-oh-my-zsh/plugins/asdf/asdf.plugin.zsh
fpath+=( /Users/carlos/Library/Caches/antibody/https-COLON--SLASH--SLASH-github.com-SLASH-robbyrussell-SLASH-oh-my-zsh/plugins/asdf )
```