Skip to content

Commit 85ef982

Browse files
author
Hiroki Konishi
committed
Update: merge (conflict resolved)
2 parents 3e5309a + f058238 commit 85ef982

File tree

15 files changed

+208
-218
lines changed

15 files changed

+208
-218
lines changed

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.

integration_test/integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (c *pmyTestCase) testSelf(t *testing.T) (bool, error) {
4444
return true, nil
4545
}
4646
fmt.Printf(
47-
"[%v] fail\nexpectd: %v\nactual: %v\n",
47+
"[%v] fail\nexpected: %v\nactual : %v\n",
4848
color.RedString("✘"),
4949
c.Expected,
5050
res,

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"after": "awk '{print $1}' | sed -e 's/=.*/=/g'"
99
}
1010
],
11-
"fuzzyFinderCmd": "fzf -0 -1 -q \"<query>\"",
11+
"fuzzyFinderCmd": "fzf -0 -1 --ansi -q \"<query>\"",
1212
"bufferLeft": "fzf <body>",
1313
"bufferRight": "[]"
1414
}

rules/git_pmy_rules.json

Lines changed: 7 additions & 4 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
},
@@ -33,13 +31,18 @@
3331
"stmt": "git branch --format=\"%(refname:short)\"",
3432
"after": "awk '{print $0}'"
3533
},
34+
{
35+
"tag": "🔖:tag",
36+
"stmt": "git tag",
37+
"after": "awk '{print $0}'"
38+
},
3639
{
3740
"tag": "🍺:commit",
38-
"stmt": "git log --oneline -30",
41+
"stmt": "git log --oneline -30 --color",
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: 2 additions & 7 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,23 @@
3936
"regexpLeft": "^(?P<body>.*?)(?P<path>~{0,1}([A-Za-z_\\-.]*/)+)(?P<query>[A-Za-z_\\-.]*)$",
4037
"cmdGroups": [
4138
{
42-
"tag": "",
4339
"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
{
5248
"regexpLeft": "^(?P<body>.*?) (?P<query>[A-Za-z_\\-.]*)$",
5349
"cmdGroups": [
5450
{
55-
"tag": "",
5651
"stmt": "command ls -AF -1",
5752
"after": "awk '{print $0}'"
5853
}
5954
],
60-
"fuzzyFinderCmd": "fzf -0 -1 -q \"^<query> \"",
55+
"fuzzyFinderCmd": "fzf -0 -1 --ansi -q \"^<query> \"",
6156
"bufferLeft": "<body> ",
6257
"bufferRight": "[]"
6358
}

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)