• Stars
    star
    419
  • Rank 103,397 (Top 3 %)
  • Language
    Go
  • License
    MIT License
  • Created almost 6 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

fzf-like fuzzy-finder as a Go library

go-fuzzyfinder

PkgGoDev GitHub Actions codecov

go-fuzzyfinder is a Go library that provides fuzzy-finding with an fzf-like terminal user interface.

Installation

$ go get github.com/ktr0731/go-fuzzyfinder

Usage

go-fuzzyfinder provides two functions, Find and FindMulti. FindMulti can select multiple lines. It is similar to fzf -m.

This is an example of FindMulti.

type Track struct {
    Name      string
    AlbumName string
    Artist    string
}

var tracks = []Track{
    {"foo", "album1", "artist1"},
    {"bar", "album1", "artist1"},
    {"foo", "album2", "artist1"},
    {"baz", "album2", "artist2"},
    {"baz", "album3", "artist2"},
}

func main() {
    idx, err := fuzzyfinder.FindMulti(
        tracks,
        func(i int) string {
            return tracks[i].Name
        },
        fuzzyfinder.WithPreviewWindow(func(i, w, h int) string {
            if i == -1 {
                return ""
            }
            return fmt.Sprintf("Track: %s (%s)\nAlbum: %s",
                tracks[i].Name,
                tracks[i].Artist,
                tracks[i].AlbumName)
        }))
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("selected: %v\n", idx)
}

The execution result prints selected item's indexes.

Motivation

Fuzzy-finder command-line tools such that fzf, fzy, or skim are very powerful to find out specified lines interactively. However, there are limits to deal with fuzzy-finder's features in several cases.

First, it is hard to distinguish between two or more entities that have the same text. In the example of ktr0731/itunes-cli, it is possible to conflict tracks such that same track names, but different artists. To avoid such conflicts, we have to display the artist names with each track name. It seems like the problem has been solved, but it still has the problem. It is possible to conflict in case of same track names, same artists, but other albums, which each track belongs to. This problem is difficult to solve because pipes and filters are row-based mechanisms, there are no ways to hold references that point list entities.

The second issue occurs in the case of incorporating a fuzzy-finder as one of the main features in a command-line tool such that enhancd or itunes-cli. Usually, these tools require that it has been installed one fuzzy-finder as a precondition. In addition, to deal with the fuzzy-finder, an environment variable configuration such that export TOOL_NAME_FINDER=fzf is required. It is a bother and complicated.

go-fuzzyfinder resolves above issues. Dealing with the first issue, go-fuzzyfinder provides the preview-window feature (See an example in Usage). Also, by using go-fuzzyfinder, built tools don't require any fuzzy-finders.

See Also

More Repositories

1

evans

Evans: more expressive universal gRPC client
Go
4,115
star
2

clip

A tracking helper for CLIP STUDIO PAINT files with Git
Go
63
star
3

dept

Go tool management based on Go modules
Go
24
star
4

salias

Sub-alias
Go
24
star
5

grpc-web-go-client

gRPC-Web client written in Go
Go
21
star
6

cris

Light weight file sharing application with an Ethereum smart contract (experimental app. insecure!)
Go
18
star
7

itunes-cli

Command line interface for control iTunes
Go
18
star
8

excl

A Chrome extension for closing all tabs of duplicate URLs
JavaScript
15
star
9

grpcdynamic

dynamic gRPC registration mechanism
Go
11
star
10

godoc-action

A GitHub Action that provides automated GoDoc generating and hosting
Shell
9
star
11

go-updater

update your tools by various means
Go
6
star
12

git-profile

Dead easy git profile switcher!
Go
6
star
13

apigen

Generate API client via curl
Go
5
star
14

markdownfmt

an example implementation fmt for markdown
Go
5
star
15

tweet.nvim

A simple Neovim remote plugin for Twitter written in Python3
Python
5
star
16

grpc-test

Go
4
star
17

go-semver

a library & CLI tool to manage the version of software which using semantic versioning
Go
2
star
18

prov

Shell
2
star
19

evans-demo

Go
2
star
20

dotfiles

My dotfiles
Vim Script
2
star
21

techbookfest-5-grpc-web

JavaScript
2
star
22

lgtm

CLI and library to create LGTM image from PNG/GIF
Go
2
star
23

Groover

Groover is a management Android application for Groove Coaster(In English: RYTHMVADERS)
Java
2
star
24

monkey

Code for "Writing An Interpreter In Go"
Go
1
star
25

gocon-2019-spring

Go
1
star
26

mapstruct

apply each right values to the left struct
Go
1
star
27

netflix-intro-button-killer

JavaScript
1
star
28

proto

Toy Protocol Buffers encoder/decoder implementation written in Go
Go
1
star
29

go-configure

configure anything more effectively, easily, and speedy!
Go
1
star
30

tmp

Manage your all temporary directories easily
Go
1
star
31

amadeus-kurisu

A LINE bot for Groove Coaster
JavaScript
1
star
32

panzer4reservation

Garupan ha iizo
HTML
1
star
33

git-parser

.git/objects parser for my practice
Go
1
star
34

kancolle-confirmation-dialog

don't repeat the mistake
JavaScript
1
star
35

mirage

Mirage: a simple image viewer
1
star
36

jsv

A CLI tool for validate JSON with JSON Schema
Go
1
star