diff --git a/.gitignore b/.gitignore index 3610bb6..c6be5db 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,4 @@ coverage.out vendor dist coverage.txt +antibody diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..a8e553a --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "www/themes/hugo-apex-theme"] + path = www/themes/hugo-apex-theme + url = https://github.com/caarlos0/hugo-apex-theme diff --git a/.travis.yml b/.travis.yml index 705ea06..b2423c9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,22 +1,26 @@ language: go -go: 1.9 +go: '1.10' install: - make setup - npm install -g prettier script: make ci after_success: - bash <(curl -s https://codecov.io/bash) - - gem install fpm - - test -n "$TRAVIS_TAG" && curl -sL https://git.io/goreleaser | bash - make static deploy: - provider: pages - skip_cleanup: true - github_token: $GITHUB_TOKEN - repo: getantibody/getantibody.github.io - local_dir: ./dist/getantibody.github.io - target_branch: master - on: - master: true + - provider: pages + skip_cleanup: true + github_token: $GITHUB_TOKEN + local_dir: www/public + target_branch: master + repo: getantibody/getantibody.github.io + verbose: true + on: + branch: master + - provider: script + skip_cleanup: true + script: curl -sL https://git.io/goreleaser | bash -s -- --rm-dist + on: + tags: true notifications: email: false diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 4e79b4c..314fcf7 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -8,19 +8,19 @@ In the interest of fostering an open and welcoming environment, we as contributo Examples of behavior that contributes to creating a positive environment include: -* Using welcoming and inclusive language -* Being respectful of differing viewpoints and experiences -* Gracefully accepting constructive criticism -* Focusing on what is best for the community -* Showing empathy towards other community members +- Using welcoming and inclusive language +- Being respectful of differing viewpoints and experiences +- Gracefully accepting constructive criticism +- Focusing on what is best for the community +- Showing empathy towards other community members Examples of unacceptable behavior by participants include: -* The use of sexualized language or imagery and unwelcome sexual attention or advances -* Trolling, insulting/derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or electronic address, without explicit permission -* Other conduct which could reasonably be considered inappropriate in a professional setting +- The use of sexualized language or imagery and unwelcome sexual attention or advances +- Trolling, insulting/derogatory comments, and personal or political attacks +- Public or private harassment +- Publishing others' private information, such as a physical or electronic address, without explicit permission +- Other conduct which could reasonably be considered inappropriate in a professional setting ## Our Responsibilities diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 08e9f22..6ee0cf6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -9,9 +9,9 @@ conduct](/CODE_OF_CONDUCT.md). Prerequisites are: -* Build: - * `make` - * [Go 1.8+](http://golang.org/doc/install) +- Build: + - `make` + - [Go 1.8+](http://golang.org/doc/install) Clone `antibody` from source into `$GOPATH`: diff --git a/Gopkg.lock b/Gopkg.lock index 6a795f1..490d1a3 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -2,15 +2,18 @@ [[projects]] + branch = "master" name = "github.com/alecthomas/kingpin" packages = ["."] - revision = "947dcec5ba9c011838740e680966fd7087a71d0d" - version = "v2.2.6" + revision = "a39589180ebd6bbf43076e514b55f20a95d43086" [[projects]] branch = "master" name = "github.com/alecthomas/template" - packages = [".","parse"] + packages = [ + ".", + "parse" + ] revision = "a0175ee3bccc567396460bf5acd36800cb10c49c" [[projects]] @@ -22,8 +25,8 @@ [[projects]] name = "github.com/caarlos0/gohome" packages = ["."] - revision = "677b1a663675ddb3cea3a1e232f5f0c70d39c246" - version = "v2.0" + revision = "c08fdebe2a8b9b92637a423c66ac5d4a8f4e91e8" + version = "v2.1.0" [[projects]] name = "github.com/davecgh/go-spew" @@ -45,37 +48,43 @@ [[projects]] name = "github.com/stretchr/testify" - packages = ["assert"] - revision = "69483b4bd14f5845b5a1e55bca19e954e827f1d0" - version = "v1.1.4" + packages = [ + "assert", + "require" + ] + revision = "12b6f73e6084dad08a7c6e575284b177ecafbc71" + version = "v1.2.1" [[projects]] branch = "master" name = "golang.org/x/crypto" packages = ["ssh/terminal"] - revision = "94eea52f7b742c7cbe0b03b22f0c4c8631ece122" + revision = "1a580b3eff7814fc9b40602fd35256c63b50f491" [[projects]] branch = "master" name = "golang.org/x/net" packages = ["context"] - revision = "d866cfc389cec985d6fda2859936a575a55a3ab6" + revision = "2491c5de3490fced2f6cff376127c667efeed857" [[projects]] branch = "master" name = "golang.org/x/sync" packages = ["errgroup"] - revision = "fd80eb99c8f653c847d294a001bdf2a3a6f768f5" + revision = "1d60e4601c6fd243af51cc01ddf169918a5407ca" [[projects]] branch = "master" name = "golang.org/x/sys" - packages = ["unix","windows"] - revision = "571f7bbbe08da2a8955aed9d4db316e78630e9a3" + packages = [ + "unix", + "windows" + ] + revision = "7c87d13f8e835d2fb3a70a2912c811ed0c1d241b" [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "4b140a3aac0174bdf1b16a983238e58a8ee1c504cf8fc2eebb993bc14c454196" + inputs-digest = "5b4936a2f8bcec148b0561d14a01beadd347d2669c5eda2de7291ff404f86c52" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index a6bee6a..0786e78 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -14,10 +14,6 @@ branch = "master" name = "golang.org/x/crypto" -[[constraint]] - branch = "master" - name = "golang.org/x/net" - [[constraint]] branch = "master" name = "golang.org/x/sync" diff --git a/Makefile b/Makefile index c272b7b..a37bce8 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,25 @@ SOURCE_FILES?=./... TEST_PATTERN?=. TEST_OPTIONS?= +OS=$(shell uname -s) + +export PATH := ./bin:$(PATH) # Install all the build and lint dependencies setup: - go get -u github.com/alecthomas/gometalinter - go get -u github.com/golang/dep/cmd/dep - go get -u github.com/pierrre/gotestcover - go get -u golang.org/x/tools/cmd/cover - go get -u github.com/apex/static/cmd/static-docs - dep ensure - gometalinter --install + curl -sfL https://install.goreleaser.com/github.com/gohugoio/hugo.sh | sh + curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh +ifeq ($(OS), Darwin) + brew install dep +else + curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh +endif + dep ensure -vendor-only .PHONY: setup # Run all the tests test: - gotestcover $(TEST_OPTIONS) -covermode=atomic -coverprofile=coverage.txt $(SOURCE_FILES) -run $(TEST_PATTERN) -timeout=60s + go test $(TEST_OPTIONS) -failfast -race -coverpkg=./... -covermode=atomic -coverprofile=coverage.txt $(SOURCE_FILES) -run $(TEST_PATTERN) -timeout=2m .PHONY: test # Run all the tests and opens the coverage report @@ -25,12 +29,12 @@ cover: test # Run all the linters lint: - gometalinter --vendor ./... + ./bin/golangci-lint run --enable-all ./... find . -name '*.md' -not -wholename './vendor/*' | xargs prettier -l .PHONY: lint # Run all the tests and code checks -ci: lint test +ci: build test lint .PHONY: ci # Build a beta version @@ -44,28 +48,19 @@ fmt: find . -name '*.md' -not -wholename './vendor/*' | xargs prettier --write .PHONY: fmt -# Generates the static documentation -static-gen: - @rm -rf dist/getantibody.github.io/theme - @static-docs \ - --in docs \ - --out dist/getantibody.github.io \ - --title Antibody \ - --subtitle "The fastest shell plugin manager" \ - --google UA-68164063-1 -.PHONY: static-gen - -# Downloads and generates the static documentation +# Generate the static documentation static: - @rm -rf dist/getantibody.github.io - @mkdir -p dist - @git clone https://github.com/getantibody/getantibody.github.io.git dist/getantibody.github.io - @make static-gen + @hugo --enableGitInfo --source www .PHONY: static -# Opens the current docs on the default browser -static-open: - open dist/getantibody.github.io/index.html -.PHONY: static-open +serve: + @hugo server --enableGitInfo --watch --source www +.PHONY: serve + +favicon: + wget -O www/static/avatar.png https://avatars2.githubusercontent.com/u/16625397 + convert www/static/avatar.png -define icon:auto-resize=64,48,32,16 www/static/favicon.ico + convert www/static/avatar.png -resize x120 www/static/apple-touch-icon.png +.PHONY: favicon .DEFAULT_GOAL := build diff --git a/README.md b/README.md index c91ec70..034fad2 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@
-
+
@@ -21,23 +21,23 @@ performance.
## Documentation
-Documentation can be found in the [docs folder](docs) and live
+Documentation can be found in the [docs folder](www/content) and live
at https://getantibody.github.io
## In the wild
-* I did this mostly for myself, so, my [dotfiles](https://github.com/caarlos0/dotfiles);
-* @mkwmms' [dotfiles](https://github.com/mkwmms/dotfiles);
-* @oieduardorabelo's [dotfiles](https://github.com/oieduardorabelo/dotfiles);
-* @nisaacson's [dotfiles](https://github.com/nisaacson/dotfiles);
-* @pragmaticivan's [dotfiles](https://github.com/pragmaticivan/dotfiles);
-* @wkentaro's [dotfiles](https://github.com/wkentaro/dotfiles);
-* @marceldias' [dotfiles](https://github.com/marceldiass/dotfiles);
-* @davidkna's [dotfiles](https://github.com/davidkna/dotfiles);
-* @sobolevn's [dotfiles](https://github.com/sobolevn/dotfiles);
-* and probably [many others](https://github.com/search?q=antibody&type=Code);
+- I did this mostly for myself, so, my [dotfiles](https://github.com/caarlos0/dotfiles);
+- @mkwmms' [dotfiles](https://github.com/mkwmms/dotfiles);
+- @oieduardorabelo's [dotfiles](https://github.com/oieduardorabelo/dotfiles);
+- @nisaacson's [dotfiles](https://github.com/nisaacson/dotfiles);
+- @pragmaticivan's [dotfiles](https://github.com/pragmaticivan/dotfiles);
+- @wkentaro's [dotfiles](https://github.com/wkentaro/dotfiles);
+- @marceldias' [dotfiles](https://github.com/marceldiass/dotfiles);
+- @davidkna's [dotfiles](https://github.com/davidkna/dotfiles);
+- @sobolevn's [dotfiles](https://github.com/sobolevn/dotfiles);
+- and probably [many others](https://github.com/search?q=antibody&type=Code);
## Thanks
-* [@pragmaticivan](https://github.com/pragmaticivan), for the logo design;
-* All the amazing [contributors](https://github.com/getantibody/antibody/graphs/contributors).
+- [@pragmaticivan](https://github.com/pragmaticivan), for the logo design;
+- All the amazing [contributors](https://github.com/getantibody/antibody/graphs/contributors).
diff --git a/antibodylib/antibody.go b/antibodylib/antibody.go
index 4fe292f..c45ff6c 100644
--- a/antibodylib/antibody.go
+++ b/antibodylib/antibody.go
@@ -51,7 +51,7 @@ func (a *Antibody) Bundle() (result string, err error) {
}
s, berr := bundle.New(a.Home, l).Get()
lock.Lock()
- shs = append(shs, indexedLine{index, s})
+ shs = append(shs, indexedLine{idx: index, line: s})
lock.Unlock()
return berr
})
diff --git a/antibodylib/antibody_test.go b/antibodylib/antibody_test.go
index ac856e1..dc9c19a 100644
--- a/antibodylib/antibody_test.go
+++ b/antibodylib/antibody_test.go
@@ -9,7 +9,7 @@ import (
"testing"
"github.com/getantibody/antibody/antibodylib"
- "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestAntibody(t *testing.T) {
@@ -29,22 +29,23 @@ func TestAntibody(t *testing.T) {
bytes.NewBufferString(strings.Join(bundles, "\n")),
runtime.NumCPU(),
).Bundle()
- assert.NoError(t, err)
+ require.NoError(t, err)
files, err := ioutil.ReadDir(home)
- assert.NoError(t, err)
- assert.Len(t, files, 3)
- assert.Contains(t, sh, `export PATH="/tmp:$PATH"`)
- assert.Contains(t, sh, `export PATH="`+home+`/https-COLON--SLASH--SLASH-github.com-SLASH-caarlos0-SLASH-ports:$PATH"`)
- assert.Contains(t, sh, `export PATH="`+home+`/https-COLON--SLASH--SLASH-github.com-SLASH-caarlos0-SLASH-jvm:$PATH"`)
- assert.Contains(t, sh, `source `+home+`/https-COLON--SLASH--SLASH-github.com-SLASH-caarlos0-SLASH-zsh-open-pr/git-open-pr.plugin.zsh`)
+ require.NoError(t, err)
+ require.Len(t, files, 3)
+ require.Contains(t, sh, `export PATH="/tmp:$PATH"`)
+ require.Contains(t, sh, `export PATH="`+home+`/https-COLON--SLASH--SLASH-github.com-SLASH-caarlos0-SLASH-ports:$PATH"`)
+ require.Contains(t, sh, `export PATH="`+home+`/https-COLON--SLASH--SLASH-github.com-SLASH-caarlos0-SLASH-jvm:$PATH"`)
+ // nolint: lll
+ require.Contains(t, sh, `source `+home+`/https-COLON--SLASH--SLASH-github.com-SLASH-caarlos0-SLASH-zsh-open-pr/git-open-pr.plugin.zsh`)
}
func TestAntibodyError(t *testing.T) {
home := home()
bundles := bytes.NewBufferString("invalid-repo")
sh, err := antibodylib.New(home, bundles, runtime.NumCPU()).Bundle()
- assert.Error(t, err)
- assert.Empty(t, sh)
+ require.Error(t, err)
+ require.Empty(t, sh)
}
func TestMultipleRepositories(t *testing.T) {
@@ -65,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",
@@ -75,17 +78,57 @@ func TestMultipleRepositories(t *testing.T) {
bytes.NewBufferString(strings.Join(bundles, "\n")),
runtime.NumCPU(),
).Bundle()
- assert.NoError(t, err)
- assert.Len(t, strings.Split(sh, "\n"), 16)
+ require.NoError(t, err)
+ require.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()
+ require.NoError(b, err)
+ }
}
func TestHome(t *testing.T) {
- assert.Contains(t, antibodylib.Home(), "antibody")
+ require.Contains(t, antibodylib.Home(), "antibody")
}
func TestHomeFromEnvironmentVariable(t *testing.T) {
- assert.NoError(t, os.Setenv("ANTIBODY_HOME", "/tmp"))
- assert.Equal(t, "/tmp", antibodylib.Home())
+ require.NoError(t, os.Setenv("ANTIBODY_HOME", "/tmp"))
+ require.Equal(t, "/tmp", antibodylib.Home())
}
func home() string {
diff --git a/antibodylib/sort.go b/antibodylib/sort.go
index ed36989..a22dff9 100644
--- a/antibodylib/sort.go
+++ b/antibodylib/sort.go
@@ -30,6 +30,7 @@ func (slice indexedLines) Swap(i, j int) {
// Sort all lines and join them in a string
func (slice indexedLines) String() string {
sort.Sort(slice)
+ // nolint: prealloc
var lines []string
for _, line := range slice {
lines = append(lines, line.line)
diff --git a/bundle/bundle.go b/bundle/bundle.go
index f7d0fd4..dddb179 100644
--- a/bundle/bundle.go
+++ b/bundle/bundle.go
@@ -29,12 +29,12 @@ func New(home, line string) Bundle {
kind := extract(line)
proj := project.New(home, line)
if kind == "path" {
- return pathBundle{proj}
+ return pathBundle{Project: proj}
}
if kind == "dummy" {
- return dummyBundle{proj}
+ return dummyBundle{Project: proj}
}
- return zshBundle{proj}
+ return zshBundle{Project: proj}
}
func extract(line string) string {
diff --git a/bundle/bundle_test.go b/bundle/bundle_test.go
index 7f7bf21..13d3bdf 100644
--- a/bundle/bundle_test.go
+++ b/bundle/bundle_test.go
@@ -6,7 +6,7 @@ import (
"testing"
"github.com/getantibody/antibody/bundle"
- "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestSuccessfullGitBundles(t *testing.T) {
@@ -15,7 +15,7 @@ func TestSuccessfullGitBundles(t *testing.T) {
}{
{
"caarlos0/jvm",
- "jvm.plugin.zsh",
+ "jvm.plugin.zsh\nfpath+=( ",
},
{
"caarlos0/jvm kind:path",
@@ -36,10 +36,11 @@ func TestSuccessfullGitBundles(t *testing.T) {
}
for _, row := range table {
t.Run(row.line, func(t *testing.T) {
+ t.Parallel()
home := home()
result, err := bundle.New(home, row.line).Get()
- assert.Contains(t, result, row.result)
- assert.NoError(t, err)
+ require.Contains(t, result, row.result)
+ require.NoError(t, err)
})
}
}
@@ -47,41 +48,41 @@ func TestSuccessfullGitBundles(t *testing.T) {
func TestZshInvalidGitBundle(t *testing.T) {
home := home()
_, err := bundle.New(home, "doesnt exist").Get()
- assert.Error(t, err)
+ require.Error(t, err)
}
func TestZshLocalBundle(t *testing.T) {
home := home()
- assert.NoError(t, ioutil.WriteFile(home+"/a.sh", []byte("echo 9"), 0644))
+ require.NoError(t, ioutil.WriteFile(home+"/a.sh", []byte("echo 9"), 0644))
result, err := bundle.New(home, home).Get()
- assert.Contains(t, result, "a.sh")
- assert.NoError(t, err)
+ require.Contains(t, result, "a.sh")
+ require.NoError(t, err)
}
func TestZshInvalidLocalBundle(t *testing.T) {
home := home()
_, err := bundle.New(home, "/asduhasd/asdasda").Get()
- assert.Error(t, err)
+ require.Error(t, err)
}
func TestZshBundleWithNoShFiles(t *testing.T) {
home := home()
_, err := bundle.New(home, "getantibody/antibody").Get()
- assert.NoError(t, err)
+ require.NoError(t, err)
}
func TestPathInvalidLocalBundle(t *testing.T) {
home := home()
_, err := bundle.New(home, "/asduhasd/asdasda kind:path").Get()
- assert.Error(t, err)
+ require.Error(t, err)
}
func TestPathLocalBundle(t *testing.T) {
home := home()
- assert.NoError(t, ioutil.WriteFile(home+"whatever.sh", []byte(""), 0644))
+ require.NoError(t, ioutil.WriteFile(home+"whatever.sh", []byte(""), 0644))
result, err := bundle.New(home, home+" kind:path").Get()
- assert.Equal(t, "export PATH=\""+home+":$PATH\"", result)
- assert.NoError(t, err)
+ require.Equal(t, "export PATH=\""+home+":$PATH\"", result)
+ require.NoError(t, err)
}
func home() string {
diff --git a/bundle/zsh.go b/bundle/zsh.go
index 2f346b9..0ba2679 100644
--- a/bundle/zsh.go
+++ b/bundle/zsh.go
@@ -1,6 +1,7 @@
package bundle
import (
+ "fmt"
"os"
"path/filepath"
"strings"
@@ -38,7 +39,7 @@ func (bundle zshBundle) Get() (result string, err error) {
for _, file := range files {
lines = append(lines, "source "+file)
}
-
+ lines = append(lines, fmt.Sprintf("fpath+=( %s )", bundle.Project.Folder()))
return strings.Join(lines, "\n"), err
}
diff --git a/goreleaser.yml b/goreleaser.yml
index f097f52..fe54952 100644
--- a/goreleaser.yml
+++ b/goreleaser.yml
@@ -2,6 +2,7 @@ build:
goos:
- linux
- darwin
+ - freebsd
goarch:
- 386
- amd64
@@ -24,7 +25,7 @@ brew:
description: The fastest shell plugin manager
dependencies:
- git
-fpm:
+nfpm:
homepage: http://getantibody.github.io
description: The fastest shell plugin manager
maintainer: Carlos Alexandro Becker