Skip to content

Commit 7ba2256

Browse files
authored
Merge pull request #12 from relastle/develop
Make all command execution online 🎉
2 parents 2096cc4 + 74cc4a9 commit 7ba2256

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+827
-230
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
pmy
22
tags
3+
4+
# Mypy cache directory
5+
.mypy_cache/

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ I'm fully in love with fzf, and I think [zsh's completion system](http://zsh.sou
1414

1515
- [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.)
1616
- [go](https://github.com/golang/go)
17-
- [go-shellwords](https://github.com/mattn/go-shellwords)
18-
- [go-pipeline](https://github.com/mattn/go-pipeline)
19-
- [color](https://github.com/fatih/color) (Used in test)
17+
- [color](https://github.com/fatih/color)
2018

2119
- awk (available in almost all environment.)
2220

cmd/taggo/flag.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"log"
6+
)
7+
8+
var (
9+
tag string
10+
colorStr string
11+
delimiter string
12+
index int
13+
)
14+
15+
func checkColor() bool {
16+
ks := []string{}
17+
for k := range colorFuncMap {
18+
if colorStr == k {
19+
return true
20+
}
21+
ks = append(ks, k)
22+
}
23+
log.Fatalf("color must be any of %v\n", ks)
24+
return false
25+
}
26+
27+
func parse() {
28+
flag.StringVar(&tag, "tag", "", "")
29+
flag.StringVar(&colorStr, "color", "black", "")
30+
flag.StringVar(&delimiter, "delimiter", "\t", "")
31+
flag.IntVar(&index, "index", -1, "")
32+
flag.Parse()
33+
// Validation
34+
checkColor()
35+
}

cmd/taggo/main.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
"fmt"
6+
"os"
7+
"strings"
8+
9+
"github.com/fatih/color"
10+
)
11+
12+
func asItIs(format string, a ...interface{}) string {
13+
return format
14+
}
15+
16+
var colorFuncMap = map[string](func(format string, a ...interface{}) string){
17+
"": asItIs,
18+
"balck": color.BlackString,
19+
"red": color.RedString,
20+
"green": color.BlueString,
21+
"yellow": color.YellowString,
22+
"blue": color.CyanString,
23+
"magenda": color.MagentaString,
24+
"cyan": color.CyanString,
25+
"white": color.WhiteString,
26+
}
27+
28+
func main() {
29+
parse()
30+
color.NoColor = false
31+
scanner := bufio.NewScanner(os.Stdin)
32+
for scanner.Scan() {
33+
text := scanner.Text()
34+
if index >= 0 {
35+
elms := strings.Split(text, delimiter)
36+
fmt.Printf(
37+
"%v%v%v\n",
38+
colorFuncMap[colorStr](elms[0]),
39+
delimiter,
40+
strings.Join(elms[1:len(elms)], delimiter),
41+
)
42+
} else {
43+
fmt.Printf(
44+
"%v%v%v\n",
45+
colorFuncMap[colorStr](tag),
46+
delimiter,
47+
text,
48+
)
49+
}
50+
}
51+
52+
if scanner.Err() != nil {
53+
}
54+
}

cmd/taggo/taggo

2.22 MB
Binary file not shown.

docker/Dockerfile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,9 @@ RUN go get -u github.com/junegunn/fzf
1313

1414
# Install pmy
1515
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
16+
RUN go get github.com/fatih/color
2017
COPY . .
21-
RUN go build
18+
RUN go install ./...
2219
RUN ln -s "/go/src/github.com/relastle/pmy/shell/zshrc.minimal" "${HOME}/.zshrc"
2320

2421

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+
]

0 commit comments

Comments
 (0)