Skip to content

Instantly share code, notes, and snippets.

@junegunn
Created May 7, 2024 14:50
Show Gist options
  • Select an option

  • Save junegunn/193990b65be48a38aac6ac49d5669170 to your computer and use it in GitHub Desktop.

Select an option

Save junegunn/193990b65be48a38aac6ac49d5669170 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"os"
fzf "github.com/junegunn/fzf/src"
)
func main() {
inputChan := make(chan string)
go func() {
for _, s := range []string{"a", "b", "c"} {
inputChan <- s
}
close(inputChan)
}()
outputChan := make(chan string)
go func() {
for s := range outputChan {
fmt.Println("Got: " + s)
}
}()
exit := func(code int, err error) {
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
}
os.Exit(code)
}
// Build fzf.Options
options, err := fzf.ParseOptions(
true, // whether to load defaults ($FZF_DEFAULT_OPTS_FILE and $FZF_DEFAULT_OPTS)
[]string{"--multi", "--reverse", "--border", "--height=40%"},
)
if err != nil {
exit(fzf.ExitError, err)
}
// Set up input and output channels
options.Input = inputChan
options.Output = outputChan
// Run fzf
code, err := fzf.Run(options)
exit(code, err)
}
@OakNinja
Copy link

OakNinja commented Jan 7, 2026

I used this code sample when I rewrote my tool MakeMeFish into a cross-shell tool, MakeMe: https://github.com/OakNinja/MakeMe

I wrote a blog post about the conversion (GutHub pages, no tracking) here: https://blog.oak.ninja/development/2026/01/02/makeme-a-cross-shell-makefile-navigator.html

If you want to write a tool and use fzf as a lib, reach out / quote me and I'd be happy to help. fzf is extremely powerful and should be utilized by everyone and everything :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment