Logo

dev-resources.site

for different kinds of informations.

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

Published at
12/12/2024
Categories
learning
tooling
bash
cheatsheet
Author
melopilosyan
Categories
4 categories in total
learning
open
tooling
open
bash
open
cheatsheet
open
Author
12 person written this
melopilosyan
open
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 ...".

bash Article's
30 articles in total
Favicon
Understanding Linux Shells: Interactive, Non-Interactive, and RC Files
Favicon
Fixing Linux Backup Sync Issues for exFAT Compatibility
Favicon
Ergonomic Pyhon Text Piping Solution for Linux Shell with pypyp and uv
Favicon
Changing the Login Shell with Security and Interactivity
Favicon
Final Bash Script Series Mastering Remote Server Management and Web App Deployment
Favicon
Writting a GH extension with AI
Favicon
Test GPIO pins on BeagleBone Black by toggling high to low
Favicon
NYP Infosec December CTF 2024 writeup!
Favicon
Building a Smart Heater Controller with Python, Docker, and Bluetooth #3
Favicon
The Complete Guide to Bash Commands
Favicon
How to Get Started with Bash Scripting for Automation
Favicon
Building a Basic Testing Framework in Bash ๐Ÿš
Favicon
Funny how, as I was writing this, I started wonderingโ€”could we make this pipeline even smarter? Thatโ€™s when SonarQube came to mind. But can it even work with Bash scripts? Iโ€™d love to hear your thoughts!
Favicon
Domina Bash con ejemplos prรกcticos de Git
Favicon
Explaining Null Device or Black Hole Register in Vim
Favicon
A Media Server on Steroids - Walkthrough
Favicon
From FZF file preview to a browser for cht.sh to discovering the ideal solution
Favicon
Code. Battery notifier.
Favicon
๐ŸŒŸSimplifying User Account Management with Bash Scripting Day3๐ŸŒŸ
Favicon
Become a Bash Scripting Pro in 10 Minutes: A Quick Guide for Beginners
Favicon
Automatically Monitor and Manage RAM Usage for Next.js Development
Favicon
Bash Script - Task Management
Favicon
Bash Your Tools
Favicon
Bash Script Series: Automating Log Analysis with Bash Script or Shell Script
Favicon
The Most Interesting Mostly Tech Reads of 2024
Favicon
๐Ÿš€ Automating Process Monitoring & Restarting with Bash Scripting Day4! ๐Ÿ”ง
Favicon
๐Ÿš€ RazzShell v1.0.1 is Here: Plugin Support, Enhanced Job Management, and More! ๐ŸŒŸ
Favicon
Step-by-Step Guide: Assigning a Namecheap Domain to DigitalOcean Hosting with Nginx
Favicon
Simplify GitHub Workflow Management with My-GitHub-Manager
Favicon
How to play a bunch of lemmings

Featured ones: