DEV Community

Cover image for From FZF file preview to a browser for cht.sh to discovering the ideal solution
Meliq Pilosyan
Meliq Pilosyan

Posted on

From FZF file preview to a browser for cht.sh to discovering the ideal solution

Very few scientific discoveries, if any, ever begin with "Eureka".
It's "that's funny ...".
— Isaac Asimov (possibly (paraphrased by Neil deGrasse Tyson))

A story about the cycle of learning, following a hunch, further exploration and discovery along the way.


After setting up the FZF to my liking: changing the theme, adding the file preview and some aliases, I was happily using it until the next time I looked up information on cht.sh.

Don't get me wrong, the outcome is more satisfying. It was the feeling of realization that a new project was unfolding right then, sparked by curiosity and excitement.

You see, the way the cht.sh API is designed with its :lists of topics and subtopics makes it a perfect candidate for browsing it with FZF.

It did took me a few iterations to finalize the spec, decide on the trade-offs (I had to say no to supporting some of the cht.sh's features for the sake simplicity), but in the end I made myself a useful tool. Well, two, actually. So naturally I'm in a happy user mode again.

Let's start with the browser. It's a Bash script that takes user input matching the path in the cht.sh URL, downloads the file if not found in the cache, saves it for next time, and displays it with bat leveraging its conditional pager.

The fun begins when you run the script without arguments or with one ending with a slash. Now you'll be greeted by FZF with all the predefined topics listed for search and preview, if they have already been downloaded. And if not, Enter on the selected topic downloads it.

The cheat sheet for Ruby searched and previewed in the FZF browser for cht.sh

The cheat sheet for Ruby searched and previewed in the browser

Bash shortcuts cheat sheet found as a subtopic in the FZF browser for cht.sh

Bash shortcuts cheat sheet found as a subtopic

It includes several convenient features:

  • Sorting topics so the most recently downloaded ones appear first.
  • Reopening FZF with subtopics when selecting/passing a topic that ends with a slash.
  • Accepting custom queries directly from the FZF prompt.
  • Building a proper URL by escaping the input.
  • Printing the full command needed to display a cheat sheet directly, bypassing the need to search through FZF again.
  • Lastly, allows to delete cached files or remove the entire cache directory.

A fragment of the help message of the FZF browser for cht.sh

A fragment of the help message of the cheat sheets browser

Unsurprisingly, I was using the half-baked browser during its development to look up Bash's variable expansion and substitution syntax, and to refresh my memory on find, awk, and sed parameters. In hindsight, the utility has already begun to serve its purpose. What I didn't expect, however, was to find a candidate for another tool I was looking for in the middle of making this one.

The cheat sheet for bashmarks is presented as follows:

# bashmarks
# Save and jump to commonly used directories using 1 character commands.
# More information: <https://github.com/huyng/bashmarks>.
Enter fullscreen mode Exit fullscreen mode

I've tried common directory bookmarking implementations such as zoxide. But they all seem to override the cd command, which interferes with other, more important tools in my workflow. Whereas bashmarks has no automated functionality. It's not even a separate binary. But a set of a few straightforward Bash functions to manually add, delete, print and list directory bookmarks. Exactly what I needed.

I really liked the simplicity of the idea. With my newly acquired Bash skills, it was a no-brainer to copy the file and refine the implementation. I dropped zsh support and optimized it further for Bash. Added Tab completion and an optional second parameter to specify the directory path when creating new bookmarks. Renamed the g command to j and removed p altogether. Printing the path of a specific bookmark is of no use to me.

The help message of my version of bashmarks

The help message of the cheat sheets browser

Again, these are just functions that you can update as needed.

Or refer to the README of my confNest, if you'd like to use my version. The README includes installation instructions for both bashmarks and the cheat sheets browser.


As I wrapped this project up, I couldn't help but reflect on the journey — the progression of curiosity, experimentation, and discovery. It began from the decision to finally integrate the FZF into my workflow. I was curious to unlock its full potential, which led to the idea of combining it with cht.sh. In the process, I found more insights and tools, each enabling the next step.

It's funny how side projects are born — often out of questioning the status quo, wondering "what if ...".

Top comments (0)