I’ve talked previously about my initial experience with MacOS. While I still love the laptop and how well it works, my favourite applications in it have very little to do with Apple’s ecosystem — Most of them are command-line application that are shared with most of the UNIX/Linux world.
Adopting the terminal for most of my interactions allows me to be a lot more productive — I can work on multiple projects, tasks and easily switch contexts and folders.
Below are some of my currently favourite CLI applications.
oh-my-zsh is an amazing collection of zsh configurations and it comes loaded with multiple features that enhance the general usage of the terminal. These are the ones I find myself constantly using:
cd ~/d/y
and take you directly to cd ~/Downloads/YouTube
cd -
Besides the core functionality of zsh, there are plenty of plugins to choose from.
history-substring-search allows you to start typing a command, and then press up to search for all the commands that start that way.
If you find your colours to be too dull, install syntax-highlighting plugin. Now you can spot the syntax error before running the command:
And just to make your terminal a bit prettier, there is the powerful prompt. Besides being pretty it allows you to see easily your current git status and branch. Here is what mine looks like:
Part of the advantages of using the terminal, is that you don’t need a mouse… Until you need to copy something. Here are some options for mouse-less copying.
With yank all you need to copy something is redirect its output to it, like so:
Both of these commands would copy the content that was piped to them:
iTerm2 has plenty of features to make it my favorite terminal shell. Its integration feature allows you, among many other things, to easily select and copy the output of the last command:
One of my first pains when working in the command-line was: “How do I get to my project folder? Surely writing cd ~/my/very/long/path
will get old very quickly?”.
Luckily fasd can help with that (and more). Once installed and configured, it listens silently as you cd to various folders. As soon as you do, however, it remembers its path and allows you to do it much faster next time.
In the example below, I go to a directory manually. Then to go back to it, I just use fasd’s z
command and switch back.
Beside changing directories, you can also use fasd’s shortcuts for other operations using the comma (,) command, e.g:
I find lnav to be one of the best ways to cope with log files. The fact that it is also in CLI just makes it easier to work with. It effortlessly loads a single file or a whole folder with multiple log files, and allows you to filter, search and follow it very swiftly.
Here I open a folder in lnav, with many log files, and filter to get the specific lines I want:
peco is used to quickly filter the output of commands. Consider it to be the interactive version of grep
.
For example, let’s search inside my command line history to remind me syntax of git merge-base
:
Note that peco returned the selected line — That means you can use it with other applications. For example, let’s get the pid of Evernote to the clipboard with the aforementioned yank
:
I’ve started using git with a proper GUI client. As time progressed, however, I found the terminal to be faster and better for many of the common operations: checkout/pull/merge.
However, some of the operations do require interactivity. When I view git’s log I would like to move freely between commits and when committing, I’d like to be able to select the files I’d like to stage. Using a proper GUI client for that, however, is distracting — It breaks you out of the terminal and breaks the flow of the regular commands. tig helps you with that.
To watch the history, just run tig
in the directory — You will be able to view each commit, affected files and the relevant diff.
By running tig status
it is easy to stage the files you’d like to commit, or even specific lines (chunks)
Just because you’re in text mode and specifically tig, doesn’t mean you have to rely on text-mode diff. If you’re a fan of a proper diff/merge tool (e.g. Beyond Compare) it is easy to configure tig to open one. Simply add the following to your .tigrc file:
bind status <F4> !sh -c “git difftool -y \”$(git rev-parse — show-toplevel)/%(file)\”"
Now simply select a changed file and press F4
Even if you’re comfortable with the terminal, some actions can still be a chore. Quickly exploring multiple directories, copying multiple by selection to another folder, etc.
As a short example, here is how I would copy some files with ranger:
What do you do if you need to provide a certain file in the terminal to an open GUI application? For example, if you want to get the path of a photo to your photo editing program?
You could do pwd
, to get the current directory, and then append to it the name of file. But there’s an easier way.
realpath gives you the real, absolute path of any file, like so:
So you got your applications configured. What will happen once your computer dies or gets replaced? mackup (for both MacOS and Linux) is a really simple way to backup your configurations to Dropbox, or another cloud storage.
Its method is ingenious —instead of making copies and schedules, all it does is simply copies the file once to your Dropbox and replaces the original with the symlink.
The applications continue working with their configurations as usual, but they are actually modifying them on your Dropbox. Now every configuration change you do is immediately back-upped by your cloud storage.
It’s worth to emphasize — Unlike other backup applications, you only run mackup once.
This storage analyzer answers the question “What the hell is eating my drive’s space?!”. It is easy and useful and I found it much better even compared to GUI alternatives. And yes, you can delete stuff from it directly as well.
I would be happy to hear about your favorite command line applications and how you use them.
There are quite a few suggestions in the comments. I will mention the ones that I liked, but I won’t mention all of them. Sorted by how much I am likely to use them:
caffeinate sleep 5
git add
without typing long paths.