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.
- fzf
- Babashka or Clojure
Add the following to your bb.edn
or deps.edn
:
{:deps {io.github.joakimen/fzf.clj {:git/sha "2063e0f6e1a7f78b5869ef1424e04e21ec46e1eb"}}}
(require '[fzf.core :refer [fzf]])
(fzf)
;; user selects an item
"src/bbfile/core.clj"
(fzf {:multi true})
;; user selects one or more items
["src/bbfile/core.clj" "src/bbfile/cli.clj" "deps.edn"]
💡 Since
v0.0.2
, input-arguments have been moved from thein
-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"]
fzf supports a slew of options, so I have only included the ones I frequently use myself.
For all available options, see core.clj
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.
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
- Run command
Calva: Connect to a running REPL Server, not in project
- Choose
babashka
- Choose
localhost:1669
Copyright © 2023- Joakim L. Engeset
Distributed under the MIT License. See LICENSE.