Fish + Fzf make me better
One of the most overlook thing in life is incremental/marginal gain, nowadays everyone want instant gain/gratification, but sometimes to achieve something will take time, by getting better and increase efficiency at smallest details will make big different in the long run. Team sky cycling is a good example for utilise marginal gain to win cycling tours.
As a person spent most of my day in command line, I like to increase my efficiency about my command line environment, because a 3 seconds saving for a search will snowball into 4 minutes a day if I do 10 searches every hour and spend 8 hours a day on average, will turn into 24 hours time saving in a year! (Obviously this is rough estimate, but the point is the time saved)
Problems
Two of the most frequently tasks while using command line are
- Search - fuzzy search to be exact e.g you want to search file, but only remember part of the name or its path.
- Auto complete - for commands and its arguments and path to files/directories.
These tasks can be classify as finding things I want, it turn out I spent a lot of time doing and waiting for to finish.
Search -> Fzf
Imaging if you home directory and want to find a file name called “products.js” and its within the “swan” directory, there are tons directories inside your home directory, so one of the way to find such file is to use find
This will try to find everything in current directory for a file name called “products.js”, but what happen if you only remember part of the file name, you can use * in file name, but what happen if you not quite sure about the file name only remember part of the path to the file, this is fuzzy search comes in.
Fzf is a command line fuzzy finder written in Go, because its written in Go, it took adventage of its concurrency, the results is blazing fast search result. Once its installed, it can be involve using Ctrl + t then it will present a prompt for you to enter the things you remember about file, it will do fuzzy search and allow you to select the results
Fzf also provide fuzzy search within Vim, now there is more reason not to leave vim, fuzzy search is so useful in vim, now you just need to remember part of the vim and to find the file, it also give you preview the file content - this need add the follow to the vim config - (~/.vimrc)
The above basically tell fzf to preview the file content by pipe it through coderay which does code syntax hightlight then cat the output and finally only take the first few lines with head command.
Fzf can do a lot more like command line history search, vim bufffer search etc, checkout their documentation.
Auto complete -> Fish
The default shell is Bash which is a very very old shell, because people have been making hacks and workarounds for it, plus its the default shell for almost all *nix operating systems (the core of MacOs is a flavour of BSD which is similar to *nix), it has been adapt to the modern environment.
Fish is a new shell that replace bash and it can do a lot out of the box without any configuration and hacks, it can easily install with systems package manager, for MacOs
After its installed you need to either replace it as system’s default shell or manual enter it
Out of the box it already do auto complete for the path, I only type bl and it will try to find if there is blog under current directory and match it or make suggestions - hit tab, the tab completion just work and it works for command line argument as well, say if you type “git st”, it will finish “git status” for yo.
Another thing worth notice is the automatic show the branch name if you inside a git repository, all these feature out of box without any configuration. You can customise your config as well
The above command will provide a web app for its config - that’s how modern it is (its a angular web app if you wondering)! With a few clicks you can increase efficiency of your development environment.
Fish can do a lot more, the above is only tiny bit of what it can be, but its already make my life easier, there are tons features I need to discover over time!
Conclusion
With these new tools, I can spend more time on actually doing the things I want to do and solve problems, I can say after using them for awhile, I can never go back to the old way. I’m surprised how little improvement like these can actually increase my overall efficiency and make me better and happier!