An open API service indexing awesome lists of open source software.

https://github.com/sheluchin/bb-fzf

Babashka Tasks Fuzzy Picker
https://github.com/sheluchin/bb-fzf

babashka clojure fzf interactive tasks

Last synced: about 1 year ago
JSON representation

Babashka Tasks Fuzzy Picker

Awesome Lists containing this project

README

          

# bb-fzf: Select and Run Babashka Tasks with fzf

`bb-fzf` is a Babashka script that uses `fzf` to provide an interactive
interface for selecting and running Babashka tasks defined in a `bb.edn` file.
It simplifies the process of executing tasks, especially those requiring a
single argument. As a bonus, it allows you to execute your repo's bb tasks from
any sub-directory in your repo.

It uses a single dependency, [bling](https://github.com/paintparty/bling), for pretty printing.

There's a demo gif and some more writeup on my [blog][].

## Prerequisites

Before using `bb-fzf`, ensure you have the following installed:

1. **Babashka:** A native Clojure scripting environment. Installation
instructions can be found on the [Babashka website][].
2. **fzf:** A command-line fuzzy finder. Installation instructions are
available on the [fzf GitHub repository][].

## Installation

1. **Download the script:** Obtain the `bb_fzf.clj` script. You can clone
the repository or download the file directly.
2. **Make it executable:**
```bash
chmod +x bb_fzf.clj
```
3. **Place it in your PATH:** Move the script to a directory included in
your system's `PATH` environment variable (e.g., `~/.local/bin`,
`/usr/local/bin`) so you can call it from anywhere.
```bash
# Example: moving to ~/.local/bin (create if it doesn't exist)
mkdir -p ~/.local/bin
mv bb_fzf.clj ~/.local/bin/bb-fzf # Renaming for convenience
```
Ensure `~/.local/bin` is in your `PATH`. You might need to add `export
PATH="$HOME/.local/bin:$PATH"` to your shell configuration file (e.g.,
`~/.bashrc`, `~/.zshrc`) and restart your shell or run `source ~/.bashrc` /
`source ~/.zshrc`.

## Usage

Navigate to any directory containing a `bb.edn` file with defined tasks. Run
the script:

```bash
bb-fzf
```

This will launch the `fzf` interface, displaying the available public tasks from your `bb.edn`.

- Use arrow keys or type to filter and select a task.
- Press `Enter` to choose a task.
- If the selected task appears to require an argument (based on the presence of
`*command-line-args*` in its definition), you will be prompted to enter the
argument. If you don't provide one, the task will run without it.
- The script will execute the selected task using `bb [argument]`
and display the output (stdout or stderr) along with a success/error/warning
status.
- Press `Esc` in the `fzf` interface to cancel.

## Keyboard Binding (Bash Example)

To invoke `bb-fzf` easily from any directory using a keyboard shortcut, you
can add the script to your `PATH` and add a keyboard binding for it.

```bash
# adds Ctrl+b as a binding to bring up the picker
$ bind -x '"\C-b": bb_fzf.clj'
```

After setting up the binding and reloading your configuration, navigating to a
directory with a `bb.edn` and pressing your chosen shortcut (e.g., `Ctrl+B`)
should launch the `bb-fzf` interface.

[Babashka website]: https://book.babashka.org/#_installation
[fzf GitHub repository]: https://github.com/junegunn/fzf?tab=readme-ov-file#installation
[blog]: https://fnguy.com/bb-fzf.html