Skip to content

Commit

Permalink
Merge branch 'master' of github.com:gsamokovarov/jump
Browse files Browse the repository at this point in the history
  • Loading branch information
gsamokovarov committed Sep 7, 2018
2 parents f986a45 + 80837c8 commit e536fae
Show file tree
Hide file tree
Showing 33 changed files with 753 additions and 72 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: go

go:
- 1.9
- 1.11
- master

script:
Expand All @@ -12,3 +12,7 @@ matrix:
fast_finish: true
allow_failures:
- go: master

env:
global:
- GO111MODULE=on
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,26 @@ To trigger a case-sensitive search, use a term that has a capital letter.
The jump will resolve to `/Users/genadi/Development` even if there is
`/Users/genadi/Development/dev-tools` that scores better.

## Is it like autojump or z?

Yes, it is! You can import your datafile from `autojump` or `z` with:

```bash
$ jump import
```

This will try `z` first then `autojump`, so you can even combine all the
entries from both tools.

The command is safe to run on pre-existing jump database, because if an entry
exist in jump already, it won't be imported and it's score will remain
unchanged. You can be explicit and choose to import `autojump` or `z` with:

```bash
$ jump import autojump
$ jump import z
```

## Installation

Jump comes in packages for macOS through homebrew and linux.
Expand Down
11 changes: 6 additions & 5 deletions cmd/cd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import (

"github.com/gsamokovarov/assert"
"github.com/gsamokovarov/jump/cli"
"github.com/gsamokovarov/jump/config"
s "github.com/gsamokovarov/jump/scoring"
)

func Test_cdCmd(t *testing.T) {
conf := &testConfig{
conf := &config.Testing{
Entries: s.Entries{
&s.Entry{p.Join(td, "web-console"), &s.Score{Weight: 100, Age: s.Now}},
&s.Entry{p.Join(td, "/client/website"), &s.Score{Weight: 90, Age: s.Now}},
Expand All @@ -27,7 +28,7 @@ func Test_cdCmd(t *testing.T) {
}

func Test_cdCmd_noEntries(t *testing.T) {
conf := &testConfig{}
conf := &config.Testing{}

output := capture(&os.Stderr, func() {
assert.Nil(t, cdCmd(cli.Args{"wc"}, conf))
Expand All @@ -37,7 +38,7 @@ func Test_cdCmd_noEntries(t *testing.T) {
}

func Test_cdCmd_multipleArgumentsAsSeparators(t *testing.T) {
conf := &testConfig{
conf := &config.Testing{
Entries: s.Entries{
&s.Entry{p.Join(td, "web-console"), &s.Score{Weight: 100, Age: s.Now}},
&s.Entry{p.Join(td, "/client/website"), &s.Score{Weight: 90, Age: s.Now}},
Expand All @@ -52,7 +53,7 @@ func Test_cdCmd_multipleArgumentsAsSeparators(t *testing.T) {
}

func Test_cdCmd_absolutePath(t *testing.T) {
conf := &testConfig{
conf := &config.Testing{
Entries: s.Entries{
&s.Entry{p.Join(td, "web-console"), &s.Score{Weight: 100, Age: s.Now}},
&s.Entry{p.Join(td, "/client/website"), &s.Score{Weight: 90, Age: s.Now}},
Expand All @@ -71,7 +72,7 @@ func Test_cdCmd_exactMatch(t *testing.T) {
p2 := p.Join(td, "/client/website")
p3 := p.Join(td, "web")

conf := &testConfig{
conf := &config.Testing{
Entries: s.Entries{
&s.Entry{p1, &s.Score{Weight: 100, Age: s.Now}},
&s.Entry{p2, &s.Score{Weight: 90, Age: s.Now}},
Expand Down
5 changes: 3 additions & 2 deletions cmd/chdir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import (

"github.com/gsamokovarov/assert"
"github.com/gsamokovarov/jump/cli"
"github.com/gsamokovarov/jump/config"
)

func Test_chdirCmd(t *testing.T) {
p1 := p.Join(td, "web-console")
p2 := p.Join(td, "/client/website")

conf := &testConfig{}
conf := &config.Testing{}

entries, err := conf.ReadEntries()
assert.Nil(t, err)
Expand Down Expand Up @@ -47,7 +48,7 @@ func Test_chdirCmd(t *testing.T) {
}

func Test_chdirCmd_cwd(t *testing.T) {
conf := &testConfig{}
conf := &config.Testing{}

entries, err := conf.ReadEntries()
assert.Nil(t, err)
Expand Down
3 changes: 2 additions & 1 deletion cmd/clean_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (

"github.com/gsamokovarov/assert"
"github.com/gsamokovarov/jump/cli"
"github.com/gsamokovarov/jump/config"
)

func Test_cleanCmd(t *testing.T) {
conf := &testConfig{}
conf := &config.Testing{}

assert.Nil(t, chdirCmd(cli.Args{"/inexistent/dir/dh891n2kisdha"}, conf))

Expand Down
47 changes: 0 additions & 47 deletions cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,10 @@ import (
"io/ioutil"
"os"
"path"

"github.com/gsamokovarov/jump/config"
"github.com/gsamokovarov/jump/scoring"
)

var td string

type testConfig struct {
Entries scoring.Entries
Search config.Search
Pins map[string]string
Pin string
}

func (c *testConfig) ReadEntries() (scoring.Entries, error) {
return c.Entries, nil
}

func (c *testConfig) WriteEntries(entries scoring.Entries) error {
c.Entries = entries
return nil
}

func (c *testConfig) ReadSearch() config.Search {
return c.Search
}

func (c *testConfig) WriteSearch(term string, index int) error {
c.Search.Term = term
c.Search.Index = index
return nil
}

func (c *testConfig) ReadPins() (map[string]string, error) {
return c.Pins, nil
}

func (c *testConfig) FindPin(term string) (string, bool) {
return c.Pin, c.Pin != ""
}

func (c *testConfig) WritePin(_, value string) error {
c.Pin = value
return nil
}

func (c *testConfig) RemovePin(term string) error {
c.Pin = ""
return nil
}

func capture(stream **os.File, fn func()) string {
rescue := *stream
r, w, _ := os.Pipe()
Expand Down
3 changes: 2 additions & 1 deletion cmd/forget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import (

"github.com/gsamokovarov/assert"
"github.com/gsamokovarov/jump/cli"
"github.com/gsamokovarov/jump/config"
"github.com/gsamokovarov/jump/scoring"
)

func Test_forgetCmd(t *testing.T) {
p := p.Join(td, "web-console")

conf := &testConfig{
conf := &config.Testing{
Entries: scoring.Entries{scoring.NewEntry(p)},
}

Expand Down
1 change: 1 addition & 0 deletions cmd/help_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func Example_helpCmd() {
// clean Cleans the database of inexisting entries.
// forget Removes the current directory from the database.
// hint Hints relevant paths for jumping.
// import Import autojump or z scores.
// pin Pin a directory to a search term.
// pins Lists all the pinned search terms.
// shell Display a shell integration script.
Expand Down
5 changes: 3 additions & 2 deletions cmd/hint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import (

"github.com/gsamokovarov/assert"
"github.com/gsamokovarov/jump/cli"
"github.com/gsamokovarov/jump/config"
s "github.com/gsamokovarov/jump/scoring"
)

func Test_hintCmd_short(t *testing.T) {
p1 := p.Join(td, "web-console")
p2 := p.Join(td, "/client/website")

conf := &testConfig{
conf := &config.Testing{
Entries: s.Entries{
&s.Entry{p2, &s.Score{Weight: 90, Age: s.Now}},
&s.Entry{p1, &s.Score{Weight: 100, Age: s.Now}},
Expand All @@ -33,7 +34,7 @@ func Test_hintCmd_short(t *testing.T) {
}

func Test_hintCmd_noEntries(t *testing.T) {
conf := &testConfig{}
conf := &config.Testing{}

output := capture(&os.Stdout, func() {
assert.Nil(t, hintCmd(cli.Args{"webcons"}, conf))
Expand Down
20 changes: 20 additions & 0 deletions cmd/import.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cmd

import (
"github.com/gsamokovarov/jump/cli"
"github.com/gsamokovarov/jump/config"
"github.com/gsamokovarov/jump/importer"
"github.com/gsamokovarov/jump/scoring"
)

func importCmd(args cli.Args, conf config.Config) error {
imp := importer.Guess(args.CommandName(), conf)

return imp.Import(func(entry *scoring.Entry) {
cli.Outf("Importing %s\n", entry.Path)
})
}

func init() {
cli.RegisterCommand("import", "Import autojump or z scores.", importCmd)
}
79 changes: 79 additions & 0 deletions cmd/import_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package cmd

import (
"os"
"testing"

"github.com/gsamokovarov/assert"
"github.com/gsamokovarov/jump/cli"
"github.com/gsamokovarov/jump/config"
)

func Test_importCmd_autojump(t *testing.T) {
oldHOME := os.Getenv("HOME")
defer os.Setenv("HOME", oldHOME)

os.Setenv("HOME", td)

conf := &config.Testing{}

output := capture(&os.Stdout, func() {
assert.Nil(t, importCmd(cli.Args{"autojump"}, conf))
})

assert.Equal(t, `Importing /Users/genadi/Development/jump
Importing /Users/genadi/Development/mock_last_status
Importing /Users/genadi/Development
Importing /Users/genadi/.go/src/github.com/gsamokovarov/jump
Importing /usr/local/Cellar/autojump
Importing /Users/genadi/Development/gloat
`, output)

assert.Len(t, 6, conf.Entries)
}

func Test_importCmd_z(t *testing.T) {
oldHOME := os.Getenv("HOME")
defer os.Setenv("HOME", oldHOME)

os.Setenv("HOME", td)

conf := &config.Testing{}

output := capture(&os.Stdout, func() {
assert.Nil(t, importCmd(cli.Args{"z"}, conf))
})

assert.Equal(t, `Importing /Users/genadi/Development/hack
Importing /Users/genadi/Development/masse
Importing /Users/genadi/Development
Importing /Users/genadi/.go/src/github.com/gsamokovarov/jump
`, output)

assert.Len(t, 4, conf.Entries)
}

func Test_importCmd_itALL(t *testing.T) {
oldHOME := os.Getenv("HOME")
defer os.Setenv("HOME", oldHOME)

os.Setenv("HOME", td)

conf := &config.Testing{}

output := capture(&os.Stdout, func() {
assert.Nil(t, importCmd(cli.Args{""}, conf))
})

assert.Equal(t, `Importing /Users/genadi/Development/hack
Importing /Users/genadi/Development/masse
Importing /Users/genadi/Development
Importing /Users/genadi/.go/src/github.com/gsamokovarov/jump
Importing /Users/genadi/Development/jump
Importing /Users/genadi/Development/mock_last_status
Importing /usr/local/Cellar/autojump
Importing /Users/genadi/Development/gloat
`, output)

assert.Len(t, 8, conf.Entries)
}
5 changes: 3 additions & 2 deletions cmd/pin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import (

"github.com/gsamokovarov/assert"
"github.com/gsamokovarov/jump/cli"
"github.com/gsamokovarov/jump/config"
s "github.com/gsamokovarov/jump/scoring"
)

func Test_pinCmd(t *testing.T) {
p1 := p.Join(td, "web")
p2 := p.Join(td, "web-console")

conf := &testConfig{
conf := &config.Testing{
Entries: s.Entries{
&s.Entry{p2, &s.Score{Weight: 1, Age: s.Now}},
&s.Entry{p1, &s.Score{Weight: 100, Age: s.Now}},
Expand All @@ -34,7 +35,7 @@ func Test_pinCmd_normalizedTerms(t *testing.T) {
p1 := p.Join(td, "web")
p2 := p.Join(td, "web-console")

conf := &testConfig{
conf := &config.Testing{
Entries: s.Entries{
&s.Entry{p2, &s.Score{Weight: 1, Age: s.Now}},
&s.Entry{p1, &s.Score{Weight: 100, Age: s.Now}},
Expand Down
3 changes: 2 additions & 1 deletion cmd/pins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
"testing"

"github.com/gsamokovarov/assert"
"github.com/gsamokovarov/jump/config"
)

func Test_pinsCmd(t *testing.T) {
conf := &testConfig{
conf := &config.Testing{
Pins: map[string]string{
"r": "/home/user/projects/rails",
},
Expand Down
6 changes: 6 additions & 0 deletions cmd/testdata/.local/share/autojump/autojump.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
38.729833462 /Users/genadi/Development/jump
14.1421356237 /Users/genadi/Development/mock_last_status
33.1662479035 /Users/genadi/Development
14.1421356237 /Users/genadi/.go/src/github.com/gsamokovarov/jump
43.5889894353 /usr/local/Cellar/autojump
20.0 /Users/genadi/Development/gloat
4 changes: 4 additions & 0 deletions cmd/testdata/.z
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/Users/genadi/Development/hack|11|1536272816
/Users/genadi/Development/masse|1|1536272502
/Users/genadi/Development|3|1536272506
/Users/genadi/.go/src/github.com/gsamokovarov/jump|1|1536272492

0 comments on commit e536fae

Please sign in to comment.