https://github.com/joakimen/fzf.clj
A small, data-driven and babashka-compatible wrapper around fzf
https://github.com/joakimen/fzf.clj
babashka clojure fzf
Last synced: about 2 months ago
JSON representation
A small, data-driven and babashka-compatible wrapper around fzf
- Host: GitHub
- URL: https://github.com/joakimen/fzf.clj
- Owner: joakimen
- License: mit
- Created: 2023-05-29T16:49:28.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-09-03T09:20:32.000Z (about 1 year ago)
- Last Synced: 2025-08-12T19:51:07.649Z (about 2 months ago)
- Topics: babashka, clojure, fzf
- Language: Clojure
- Homepage:
- Size: 62.5 KB
- Stars: 23
- Watchers: 4
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fzf.clj
[](https://choosealicense.com/licenses/mit/) [](https://github.com/joakimen/fzf.clj/actions/workflows/ci.yml) [](https://babashka.org)
A small wrapper around [fzf](https://github.com/junegunn/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](https://github.com/junegunn/fzf)
- Babashka or Clojure## Usage
Add the following to your `bb.edn` or `deps.edn`:
```edn
{:deps {io.github.joakimen/fzf.clj {:git/sha "2063e0f6e1a7f78b5869ef1424e04e21ec46e1eb"}}}
```### Example usage
#### Import
```clojure
(require '[fzf.core :refer [fzf]])
```#### Single selection
```clojure
(fzf)
;; user selects an item
"src/bbfile/core.clj"
```#### Multi-selection
```clojure
(fzf {:multi true})
;; user selects one or more items
["src/bbfile/core.clj" "src/bbfile/cli.clj" "deps.edn"]
```#### Passing data to stdin
> :bulb: 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.
```clojure
(fzf ["one" "two" "three"])
;; user selects an item
"two"
```Threading
```clojure
(->> ["quick" "brown" "fox"] fzf) ;; => fox
```Threading w/options
```clojure
(->> ["quick" "brown" "fox"]
(map upper-case)
(fzf {:multi true})) ;; => ["QUICK" "FOX"]
```### Available options
[fzf](https://github.com/junegunn/fzf) supports a slew of options, so I have only included the ones I frequently use myself.
For all available options, see [core.clj](src/fzf/core.clj)
### Note on REPL-usage
Since [fzf](https://github.com/junegunn/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
```bash
$ 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.