Skip to content

Commit 5e2fba8

Browse files
committed
Merge branch 'develop' of https://github.com/relastle/pmy into develop
2 parents 936f250 + 91b8264 commit 5e2fba8

File tree

17 files changed

+208
-239
lines changed

17 files changed

+208
-239
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Frelastle%2Fpmy.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Frelastle%2Fpmy?ref=badge_shield)
55
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/b4d31630d2f64ef1892d74dcc2e3105e)](https://www.codacy.com/app/relastle/pmy?utm_source=github.com&utm_medium=referral&utm_content=relastle/pmy&utm_campaign=Badge_Grade)
66
[![CircleCI](https://circleci.com/gh/relastle/pmy.svg?style=shield)](https://circleci.com/gh/relastle/pmy)
7+
[![Go Report Card](https://goreportcard.com/badge/github.com/relastle/pmy)](https://goreportcard.com/report/github.com/relastle/pmy)
78

89
pmy is a highly customizable context-aware shell(zsh)-completion scheme utilizing fuzzy finder such as
910
[fzf](https://github.com/junegunn/fzf).
@@ -13,17 +14,16 @@ I'm fully in love with fzf, and I think [zsh's completion system](http://zsh.sou
1314

1415
- [fzf](https://github.com/junegunn/fzf) (You can of course use other fuzzy finder such as [peco](https://github.com/peco/peco) and [fzy](https://github.com/jhawthorn/fzy) instead of fzf.)
1516
- [go](https://github.com/golang/go)
16-
- [go-shellwords](https://github.com/mattn/go-shellwords)
17-
- [go-pipeline](https://github.com/mattn/go-pipeline)
18-
- [color](https://github.com/fatih/color) (Used in test)
17+
- [color](https://github.com/fatih/color)
1918

2019
- awk (available in almost all environment.)
2120

2221
## :hammer: Installation
2322

24-
First, please get pmy(backend system written in Go) using go get.
23+
First, please get pmy(backend system written in Go)
24+
and its dependency tool `taggo` using go get.
2525
```sh
26-
go get -u github.com/relastle/pmy
26+
go get -u github.com/relastle/pmy github.com/relastle/taggo
2727
```
2828

2929
Then, source a zsh script which simply configure brief settings.
@@ -72,7 +72,7 @@ Rule unit is described as follows
7272
| ***cmdGroups.tag*** | tag string which will be inserted ahead of each line of outputs of the corresponding command. |
7373
| ***cmdGroups.stmt*** | command that will be executed to make sources for fuzzy-finder. |
7474
| ***cmdGroups.after*** | command that will be executed against line after fuzzy-finder selection (using pipe). |
75-
| ***fuzzyFinderCmd*** | Fuzzy finder command that will be excecuted (piped) against obtained command |
75+
| ***fuzzyFinderCmd*** | Fuzzy finder command that will be executed (piped) against obtained command |
7676
| ***bufferLeft*** | Buffer left values after completion. [] denotes the original left buffer. |
7777
| ***bufferRight*** | Buffer right values after completion. [] denotes the original right buffer. |
7878

@@ -144,7 +144,7 @@ You can define such completion (with sub command description) in an very readabl
144144
| PMY_TRIGGER_KEY | Trigger key that invokes pmy completion | '^ ' |
145145
| PMY_SNIPPET_ROOT | The root directory in which pmy's snippets for magic command is located | "${GOPATH:-${HOME}/go}/src/github.com/relastle/pmy/snippets" |
146146

147-
If you want to change these values, you should export them in .zshrc before you excecute
147+
If you want to change these values, you should export them in .zshrc before you execute
148148

149149
```zsh
150150
source "${GOPATH:-${HOME}/go}/src/github.com/relastle/pmy/shell/pmy.zsh"

docker/Dockerfile

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@ ENV SHELL /bin/zsh
99

1010
# Install fzf
1111
RUN go get -u github.com/junegunn/fzf
12+
RUN go get -u github.com/relastle/taggo
1213

1314

1415
# Install pmy
1516
WORKDIR /go/src/github.com/relastle/pmy
16-
RUN go get \
17-
github.com/mattn/go-shellwords \
18-
github.com/mattn/go-pipeline \
19-
github.com/fatih/color
17+
RUN go get github.com/fatih/color
2018
COPY . .
21-
RUN go build
19+
RUN go install
2220
RUN ln -s "/go/src/github.com/relastle/pmy/shell/zshrc.minimal" "${HOME}/.zshrc"
2321

2422

integration_test/integration_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"os/exec"
1010
"strings"
1111
"testing"
12+
"time"
1213

1314
"github.com/fatih/color"
1415
)
@@ -19,7 +20,8 @@ type pmyTestCase struct {
1920
Expected string `json:"expected"`
2021
}
2122

22-
func (c *pmyTestCase) testSelf() (bool, error) {
23+
func (c *pmyTestCase) testSelf(t *testing.T) (bool, error) {
24+
start := time.Now()
2325
out, err := exec.Command(
2426
"../shell/pmy_wrapper.zsh",
2527
c.Lbuffer,
@@ -32,15 +34,17 @@ func (c *pmyTestCase) testSelf() (bool, error) {
3234

3335
res := strings.Replace(string(out), "\n", "", -1)
3436
if res == c.Expected {
37+
elapsed := time.Since(start)
3538
fmt.Printf(
36-
"[%v] pass; res: %v\n",
39+
"[%v] pass; {res: %v, elapsed: %v}\n",
3740
color.GreenString("●"),
3841
res,
42+
elapsed,
3943
)
4044
return true, nil
4145
}
4246
fmt.Printf(
43-
"[%v] fail\nexpectd: %v\nactual: %v\n",
47+
"[%v] fail\nexpected: %v\nactual : %v\n",
4448
color.RedString("✘"),
4549
c.Expected,
4650
res,
@@ -73,7 +77,7 @@ func TestIntegration(t *testing.T) {
7377
byteValue, _ := ioutil.ReadAll(jsonFile)
7478
json.Unmarshal(byteValue, &cases)
7579
for _, c := range cases {
76-
if ok, err := c.testSelf(); ok {
80+
if ok, err := c.testSelf(t); ok {
7781
continue
7882
} else if err == nil {
7983
t.Fail()

main.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ import (
77
pmy "github.com/relastle/pmy/src"
88
)
99

10+
var (
11+
bufferLeft string
12+
bufferRight string
13+
)
14+
1015
func main() {
11-
var bufferLeft string
12-
var bufferRight string
1316
flag.StringVar(&bufferLeft, "bufferLeft", "", "")
1417
flag.StringVar(&bufferRight, "bufferRight", "", "")
1518
flag.Parse()

rules/cf_pmy_rules.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"after": "awk '{print $1}'"
99
}
1010
],
11-
"fuzzyFinderCmd": "fzf -0 -q \"<query>\"",
11+
"fuzzyFinderCmd": "fzf -0 --ansi -q \"<query>\"",
1212
"bufferLeft": "<body> ",
1313
"bufferRight": "[]"
1414
},
@@ -21,7 +21,7 @@
2121
"after": "awk '{print $1}'"
2222
}
2323
],
24-
"fuzzyFinderCmd": "fzf -0",
24+
"fuzzyFinderCmd": "fzf -0 --ansi",
2525
"bufferLeft": "[]",
2626
"bufferRight": "[]"
2727
},
@@ -34,7 +34,7 @@
3434
"after": "awk '{print $1}'"
3535
}
3636
],
37-
"fuzzyFinderCmd": "fzf -0 -1 -q \"<query>\"",
37+
"fuzzyFinderCmd": "fzf -0 -1 --ansi -q \"<query>\"",
3838
"bufferLeft": "cf ",
3939
"bufferRight": "[]"
4040
}

rules/fzf_pmy_rules.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[
2+
{
3+
"regexpLeft": "^fzf (?P<body>.*)(-|--)(?P<query>.*)$",
4+
"cmdGroups": [
5+
{
6+
"tag": "",
7+
"stmt": "%fzf/option",
8+
"after": "awk '{print $1}' | sed -e 's/=.*/=/g'"
9+
}
10+
],
11+
"fuzzyFinderCmd": "fzf -0 -1 --ansi -q \"<query>\"",
12+
"bufferLeft": "fzf <body>",
13+
"bufferRight": "[]"
14+
}
15+
]

rules/git_pmy_rules.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"after": "awk '{print $1}'"
99
}
1010
],
11-
"fuzzyFinderCmd": "fzf -0 -1 ",
1211
"bufferLeft": "git ",
1312
"bufferRight": "[]"
1413
},
@@ -21,7 +20,6 @@
2120
"after": "awk '{print $1}'"
2221
}
2322
],
24-
"fuzzyFinderCmd": "fzf -0 -1 ",
2523
"bufferLeft": "git <sub_cmd><body>",
2624
"bufferRight": "[]"
2725
},
@@ -30,16 +28,21 @@
3028
"cmdGroups": [
3129
{
3230
"tag": "🌱:branch",
33-
"stmt": "git branch --format=\"%(refname:short)\"",
31+
"stmt": "git branch --format=\"%(refname:short)\" 2>/dev/null",
32+
"after": "awk '{print $0}'"
33+
},
34+
{
35+
"tag": "🔖:tag",
36+
"stmt": "git tag 2>/dev/null",
3437
"after": "awk '{print $0}'"
3538
},
3639
{
3740
"tag": "🍺:commit",
38-
"stmt": "git log --oneline -30",
41+
"stmt": "git log --oneline -30 --color 2>/dev/null",
3942
"after": "awk '{print $1}'"
4043
}
4144
],
42-
"fuzzyFinderCmd": "fzf -0 -1 -q \"<query>\"",
45+
"fuzzyFinderCmd": "fzf -0 -1 --ansi -q \"<query>\"",
4346
"bufferLeft": "<body> ",
4447
"bufferRight": "[]"
4548
},

rules/pmy_rules.json

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"regexpLeft": "(?P<body>.*?)(?P<path>~{0,1}([A-Za-z_\\-.]*/)*)\\*\\*$",
44
"cmdGroups": [
55
{
6-
"tag": "",
76
"stmt": "bfind <path>",
87
"after": "awk '{print $0}'"
98
}
@@ -15,7 +14,6 @@
1514
"regexpLeft": "^(?P<num>[1-9][0-9]*).for$",
1615
"cmdGroups": [
1716
{
18-
"tag": "",
1917
"stmt": "echo ''",
2018
"after": "awk '{print $0}'"
2119
}
@@ -27,7 +25,6 @@
2725
"regexpLeft": "(?P<cmd>.+)\\.for$",
2826
"cmdGroups": [
2927
{
30-
"tag": "",
3128
"stmt": "echo ''",
3229
"after": "awk '{print $0}'"
3330
}
@@ -39,25 +36,24 @@
3936
"regexpLeft": "^(?P<body>.*?)(?P<path>~{0,1}([A-Za-z_\\-.]*/)+)(?P<query>[A-Za-z_\\-.]*)$",
4037
"cmdGroups": [
4138
{
42-
"tag": "",
43-
"stmt": "command ls -aF -1 <path>",
39+
"stmt": "command ls -AF -1 <path>",
4440
"after": "awk '{print $0}'"
4541
}
4642
],
47-
"fuzzyFinderCmd": "fzf -0 -1 -q \"<query>\"",
43+
"fuzzyFinderCmd": "fzf -0 -1 --ansi -q \"^<query> \"",
4844
"bufferLeft": "<body><path>",
4945
"bufferRight": "[]"
5046
},
5147
{
52-
"regexpLeft": "^(?P<body>.*?) $",
48+
"regexpLeft": "^(?P<body>.*?) (?P<query>[A-Za-z_\\-.]*)$",
5349
"cmdGroups": [
5450
{
55-
"tag": "",
56-
"stmt": "bfind .",
51+
"stmt": "command ls -AF -1",
5752
"after": "awk '{print $0}'"
5853
}
5954
],
60-
"bufferLeft": "[]",
55+
"fuzzyFinderCmd": "fzf -0 -1 --ansi -q \"^<query> \"",
56+
"bufferLeft": "<body> ",
6157
"bufferRight": "[]"
6258
}
6359
]

rules/test/git_pmy_rules_test.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"after": "awk '{print $0}'"
99
}
1010
],
11-
"fuzzyFinderCmd": "fzf -0 -1 -q \"<query>\"",
11+
"fuzzyFinderCmd": "fzf -0 -1 --ansi -q \"<query>\"",
1212
"bufferLeft": "<body> ",
1313
"bufferRight": "[]"
1414
},

rules/test/pmy_testcases.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[
22
{
3-
"lbuffer": "git checkout ",
3+
"lbuffer": "git checkout mas",
44
"rbuffer": "",
55
"expected": "git checkout master"
66
},

0 commit comments

Comments
 (0)