DEV Community

Cover image for Building an IntelliSense-style Shell History Tool in C++20
Karthikey
Karthikey

Posted on

Building an IntelliSense-style Shell History Tool in C++20

The Problem: "Search" vs. "Flow"

We all live in our terminals. For years, I relied on Ctrl+R or just grepping through .zsh_history. Then tools like Atuin came along and revolutionized things by using SQLite and syncing. They are fantastic tools.

But they didn't quite fit my specific workflow.

Most modern history tools function like a Search Engine. You stop what you are doing, hit a hotkey, open a full-screen UI, search for a command, and then execute it. It feels like a context switch.

I wanted something that felt like IntelliSense. I wanted a tool that:

  1. Predicted what I wanted as I typed.
  2. Understood my context (e.g., "I'm in a Git repo on the feature/login branch").
  3. Stayed out of my way unless I needed it.

So, I built BSH (Better Shell History).

What is BSH?

BSH is a local-first, latency-critical shell history manager. It hooks into the Zsh Line Editor (ZLE) to provide a predictive overlay that updates on every single keystroke.

The Architecture: Why C++20?

To make this feel "native," latency was the enemy. If the tool takes 10ms to respond, the terminal feels "heavy." My target was <2ms per keystroke.

To achieve this, I couldn't just run a Python script or a heavy binary every time a key was pressed. I settled on a Client-Daemon Architecture:

  1. The Daemon (bsh-daemon): A background process written in C++20. It maintains an open connection to a SQLite database (in WAL mode) and holds an in-memory cache of Git repository states using libgit2.
  2. The Client (bsh): A lightweight ephemeral binary. It just serializes the keystroke, shoots it over a Unix Domain Socket to the daemon, and prints the response.
  3. The Interface: Rendered using FTXUI for the TUI overlay.

The Gap It Fills

BSH fills the gap between simple text files and heavy search engines.

  • Git Awareness: BSH knows which branch you are on. If you run specific build flags on main but different ones on dev, BSH separates those histories automatically.
  • Success Filtering: Ever search for a command, run it, and realize it was the one with the typo? BSH tracks exit codes. You can hit Ctrl+F to instantly hide all failed commands from the history.
  • Performance: By offloading the heavy lifting (SQL queries, Git parsing) to the daemon, the client stays incredibly thin.
Command Mean [ms] Relative
BSH (C++ Daemon) 1.9 ± 0.2 1.00
Standard History Tools ~5-10 ~3-5x

Where the Project Stands

Right now, BSH is in v0.2.0.

It is stable enough for daily use (I've been using it for weeks), and the core "IntelliSense" loop is solid. We just merged a major PR that optimized buffer handling using std::string_view to reduce memory allocations.

However, it is still young.

Call for Contributors

I am building this in the open because I believe developer tools should be hackable. I am looking for contributors who are interested in Systems Programming, C++, or Shell integration.

Current Roadmap / Help Needed:

  1. Bash Support: Currently, the ZLE hooks are Zsh-only. We need a Bash expert to port the scripts/bsh_init.zsh logic.
  2. Migration System: We need a way to migrate the SQLite schema gracefully between updates.
  3. Code Review: If you love optimizing C++ or finding race conditions in IPC code, I'd love your eyes on src/daemon.cpp.

Try it out

You can check out the code, read the benchmarks, or review the C++ implementation here:

https://github.com/joshikarthikey/bsh

If you try it, let me know what you think about the "IntelliSense" approach vs the standard search approach!

Top comments (0)