I spend a great deal of time in my terminal when I am using my computer. According to RescueTime I’ve spent more than 40 hours in my terminal this year.
I won’t go into a great deal of detail in this post about the things that I do, but I think it is useful to put all of the things I find really useful in one place.
Non-commands
Before you can start using the terminal you need a good terminal program. I’ve been using
iTerm for a long time. I will admit that I don’t use even half of its many
features, but I love the fact that I can click on URLs to open them in my browser, or filenames to open them in Finder, not to mention the extensive options for setting up the input methods and fonts. Multi-tab support is also amazing, and I’m always a little in awe that they took the time to display the correct history when the app restarts after a reboot.
Next I would like to mention my programming/terminal font. It’s been a long journey, but I’ve finally settled on the
Fira Code Nerd Font. I know the use of ligatures in code is a contentious issue, but I love them.
Also a shout out to my colour scheme: solarized:
Choose your shell
Almost everyone uses bash as their shell program. I switched to
zsh (using
oh-my-zsh for all the configuration) after seeing that it had more powerful tab completion out of the box and I haven’t really looked back. I highly recommend taking some time to configure (or choose a configuration for) your prompt so that it saves you time. You don’t need to do git status every time you enter a directory if the info you need is all in your prompt. In the screenshot below the green arrow to the left of the prompt shows the previous command exited successfully, the git:(master) shows me I’m in a git repo on the master branch and the cross mark shows the repo is dirty (needs files to be committed).
Commands
Of course, when you’re in the terminal, you’re going to be executing commands! I recommend learning the basic unix utilities, of course, but I’ve got some extra stuff installed that makes me much more productive. An interesting trend is that many of these extra utilities are written in Rust. I’m not sure if this is because I’m learning rust and therefore Google knows I have an affinity for Rust things or if there’s just an interesting trend of people rewriting things in rust. Whatever it is I can vouch that I am actively using every tool I recommend here:
- exa, a replacement for ls. I have aliased ls to exa and my life is better because of it. What I find particularly useful is better use of colour than ls, the ease of using ISO 8601 and built-in tree view.
- fzf, fuzzy searching everywhere. If you follow the default install instructions it will hook onto your shells ctrl-r command and supercharge it so that you can do fuzzy matching of history items. If that’s all you get from it, it’s already really great. But you can use it in lots of different ways, for instance you can just pipe a file’s contents to it to filter lines matching a fuzzy pattern. You can see what this looks like in the screenshot of my terminal above.
- bat, a cat replacement. You think “cat is so basic, how will rewriting it in Rust make it better”? Then you see the automatic line numbering, the automatic paging, the automatic syntax highlighting and you understand. I’ve just aliased both cat and less to bat and again my life is better.
- fd, for finding files. I love the find command, but its options can be a little arcane. If you’re just wanting to search for a pattern recursively, rather use fd. It understands code, so it doesn’t report hits on hidden files and blobs in your .git folder and also knows about .gitignore and will use it.
- ripgrep, for finding inside them. Another rust tool, this is just blindingly fast. ripgrep kind of replaces the combination of find and grep that you often need to do to find something in a big nested directory full of code.
- autojump, jump to your frequently-visited directories. The idea is pretty genius – hook onto the cd command and count how many times you’ve visited specific directories. Then supply a command (j) which jumps you directly there. I love that you don’t need to remember much to use it as if you only use cd it’s working fine. Then you remember “oh – I can maybe j to that directory directly” and it just works. Amazing.
- GNU parallel, which works a little bit like xargs, but has a much more friendly way of handling files with spaces and automatically parallelises calls. This tool has saved me a great deal of coding because it makes it so easy to write a program which does just one part of a task and then run it in parallel with load balancing and a nice progress bar. I cannot recommend this tool enough.
- jq, something like sed for json files. If you use json a lot, you need to get jq installed.
- jid, a good companion to jq which allows you to build your filter strings interactively and see what gets returned. It’s a bit slower, but not slower than repeatedly running jq to get just the right output
- vd, a commandline data viewer. Very good for quickly viewing tabular data, but also very deep once you get into it.