Skip to content

A small, data-driven and babashka-compatible wrapper around fzf

License

Notifications You must be signed in to change notification settings

joakimen/fzf.clj

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fzf.clj

License: MIT CI bb compatible

A small wrapper around fzf.

Intended to be used in scripts in which the user wants to select one or more items from a selection using fuzzy-completion.

Requirements

  • fzf
  • Babashka or Clojure

Usage

Add the following to your bb.edn or deps.edn:

{:deps {io.github.joakimen/fzf.clj {:git/sha "2063e0f6e1a7f78b5869ef1424e04e21ec46e1eb"}}}

Example usage

Import

(require '[fzf.core :refer [fzf]])

Single selection

(fzf)
;; user selects an item
"src/bbfile/core.clj"

Multi-selection

(fzf {:multi true})
;; user selects one or more items
["src/bbfile/core.clj" "src/bbfile/cli.clj" "deps.edn"]

Passing data to stdin

💡 Since v0.0.2, input-arguments have been moved from the in-key in the options map to its own argument to facilitate threading.

To provide input arguments to fzf via STDIN instead of using the default file selection command, the arguments can be passed as a vector of strings.

(fzf ["one" "two" "three"])
;; user selects an item
"two"

Threading

(->> ["quick" "brown" "fox"] fzf) ;; => fox

Threading w/options

(->> ["quick" "brown" "fox"]
     (map upper-case)
     (fzf {:multi true})) ;; => ["QUICK" "FOX"]

Available options

fzf supports a slew of options, so I have only included the ones I frequently use myself.

For all available options, see core.clj

Note on REPL-usage

Since fzf expects an interactive terminal in which the user nagivates and selects items, a REPL-connection using a non-interactive terminal (e.g. Calva's "Jack-In") will not render the fzf-prompt, and invocations will cause the editor to hang.

To display and work with the fzf-prompt (e.g. calling the (fzf)-function) using the REPL, the nrepl-session must be started from an interactive terminal, then connected to from the editor.

Example for Calva

Start the repl

$ bb nrepl 1669
Started nREPL server at 127.0.0.1:1669
For more info visit: https://book.babashka.org/#_nrepl

Connect to the REPL Server in VS Code

  1. Run command Calva: Connect to a running REPL Server, not in project
  2. Choose babashka
  3. Choose localhost:1669

License

Copyright © 2023- Joakim L. Engeset

Distributed under the MIT License. See LICENSE.

About

A small, data-driven and babashka-compatible wrapper around fzf

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •