Skip to content

Commit 07f6611

Browse files
committed
add fuzzy finder
1 parent caa0b0d commit 07f6611

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ require (
1313
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect
1414
github.com/inconshreveable/mousetrap v1.0.0 // indirect
1515
github.com/keybase/go-keychain v0.0.0-20181011010623-f1daa725cce4 // indirect
16+
github.com/ktr0731/go-fuzzyfinder v0.1.1
1617
github.com/mattn/go-isatty v0.0.4 // indirect
1718
github.com/mitchellh/go-homedir v1.1.0 // indirect
18-
github.com/pkg/errors v0.8.1 // indirect
1919
github.com/spf13/cobra v0.0.3
2020
github.com/stretchr/testify v1.3.0 // indirect
2121
github.com/yawn/ykoath v1.0.1

go.sum

+7
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ github.com/ebfe/scard v0.0.0-20180829124254-7c31d2fd1987 h1:KjkkybvhDJ7GCp7AM8pX
3434
github.com/ebfe/scard v0.0.0-20180829124254-7c31d2fd1987/go.mod h1:8hHvF8DlEq5kE3KWOsZQezdWq1OTOVxZArZMscS954E=
3535
github.com/godbus/dbus v4.1.0+incompatible h1:WqqLRTsQic3apZUK9qC5sGNfXthmPXzUZ7nQPrNITa4=
3636
github.com/godbus/dbus v4.1.0+incompatible/go.mod h1:/YcGZj5zSblfDWMMoOzV4fas9FZnQYTkDnsGvmh2Grw=
37+
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
3738
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU=
3839
github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0=
3940
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
@@ -42,10 +43,16 @@ github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5i
4243
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
4344
github.com/keybase/go-keychain v0.0.0-20181011010623-f1daa725cce4 h1:YB7bZpTYGkkRZrUQ6mtE9Mq0lukJDSWj5XCcd5FO6Uc=
4445
github.com/keybase/go-keychain v0.0.0-20181011010623-f1daa725cce4/go.mod h1:JJNrCn9otv/2QP4D7SMJBgaleKpOf66PnW6F5WGNRIc=
46+
github.com/ktr0731/go-fuzzyfinder v0.1.1 h1:CCpgHCVTthC2XWm2i4gM96GeCyxUIuokcW65QkXTq0M=
47+
github.com/ktr0731/go-fuzzyfinder v0.1.1/go.mod h1:RzAqRU8h8f4uSLSP+THd87krOFnBploGlGn/8RQhd7M=
4548
github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs=
4649
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
50+
github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y=
51+
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
4752
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
4853
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
54+
github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d h1:x3S6kxmy49zXVVyhcnrFqxvNVCBPb2KZ9hV2RBdS840=
55+
github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ=
4956
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
5057
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
5158
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=

prompt/fuzzy.go

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package prompt
2+
3+
import (
4+
"strings"
5+
6+
"github.com/ktr0731/go-fuzzyfinder"
7+
)
8+
9+
// WithFuzzy picks using
10+
func WithFuzzy(a Args) (int, error) {
11+
lines := make([]string, len(a.Options))
12+
for index, item := range a.Options {
13+
line := strings.Join(item, " ")
14+
lines[index] = line
15+
}
16+
17+
return fuzzyfinder.Find(lines, func(i int) string {
18+
return lines[i]
19+
})
20+
}

prompt/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type Func func(Args) (int, error)
1313
var Types = map[string]Func{
1414
"": WithDefault,
1515
"wmenu": WithWmenu,
16+
"fuzzy": WithFuzzy,
1617
}
1718

1819
// WithDefault uses the default prompt method

0 commit comments

Comments
 (0)