Something better than shell auto-complete
Why I often implement things from scratch
I had been looking for a way to do auto complete targeting a specific folder for a while. I’ve seen my colleague doing
then the shell (zsh) lists the directories from his projects folder where ever the
was. This is really cool and efficient. But I was too nerd to ask about it.
Recently I’m reading about Erlang(again), it’s Programming Erlang this time, from Joe Armstrong, father of this language. I read a lot fascinating little programs, like Pythagorean theorem, unpacking IPv4 datagram, etc. As Joe said in Why I often implement things from scratch , sometimes implement something from scratch(in erlang) might be a better idea than going to search for an existing solution. Inspired by this idea, I tried to satisfy my own demand.
After hours of working, I accomplished this: https://gist.github.com/dotSlashLu/c97ec603736a17a2c119 .
It does fuzzy(regular expression) query for the name you entered in folders you specify, if there are several matches found, it prompts to ask you for a number to choose. And if there’s only one match it directly chooses it for you.
This is not only faster and could be more efficient than the auto-complete solution I mentioned above used by my colleague. Since you just type several letters and maybe an extra number, punching a number could be much faster than pressing tab several times to select a suggestion.
It’s far from perfect right now. I may try to use trie to do some accuracy improvements. Maybe migrate from gists to github and treat it as a real project is a good idea(Update: https://github.com/dotSlashLu/bcd ).
Though I’ve written some Erlang programs, but those were just for practicing, so this one, though simple and shabby, can be regarded as the first practical program I’ve written in Erlang and I can use it every day. The more I write in Erlang, the more I like Erlang, like functional programming. I’ll write a post in the future about why Erlang and functional programming is good, but as it can be long, I’ll just record my happiness for now.
This is a small software, but it’s a good start. Think big, start small.