Srijan R. Shetty bio photo

Srijan R. Shetty

Email Twitter LinkedIn Github RSS

As engineers, we go overboard with engineering. Consider a recent bete noire was the lack of a good API to get NAV for mutual funds in India. AMFI, the association for mutual funds in India maintains a text file containing all the NAVs at open here.

The first attempt I did to query the API was to write a python behemoth to which did a simple search after converting the data into json, and is hosted here. Pleased with my prowess of python, I decided to implement fuzzy-search as well. After spending a few minutes pondering the correct interface of the commandline, I thought I should give bash a chance to solve the issue. fzf, is already all over my zsh-fu and it seemed well versed to handle this task. All I needed was to massage the data returned into something easily fed into fzf, after 10 minutes, I had the following:

get-nav () {
        http | cut -d';' -f4,5 | tr ';' '\t' | fzf

This zsh snippet makes use of httpie to download the file, cut and tr to conver the output to a format feedable to fzf and now I have generic fuzzy completion in a zsh one liner. Here’s a demo of the same:

The UNIX rule of composition and KISS have stood the test of time. It’s easy to get overboard and reinvent the wheel when you could create complex text munging in one liners of shell.