Learn to love the CLI

When I tell my students that they should use 'git' or 'mercurial' to manage their manuscripts, I always draw blanks. When I show them the few commands necessary to do so, I invariably earn stares of disbelief.

The command line. Primeval fear.

The tension subsides markedly after introducing tortoisegit and tortoisehg. Personally, I wouldn't install a GUI for the three commands necessary to locally manage a manuscript. But then, I've spend time and effort to make my stay at the command line as joyous as possible.

Shell

First of all, I need a well configured shell, and I'm not aware of any distribution which would offer one out of the box (well, perhaps grml, but that's not your typical desktop linux). I want command completion and sensible command aliases. I want an informative prompt: it should show if I'm in an hg or mercurial repository, and whether a virtual python environment is active or not. I also want to keep my typing at a minimum, i.e., a powerful history search is mandatory, and some sort of autojump feature is highly desirable.

No current shell offers all that out of the box. Many do not support these features at all. Only the "big three" may be configured such that they comply to all of my criteria: the bash (the de facto standard shell in Linux and MacOS), the zsh, and the fish.

fish

My long-time favorite is the fish, since it offers all of the above with truly minimal effort. And more!

Minimal effort? Really?

I speaketh the truth. I only had to...

...define some elementary aliases, such as

alias c "clear"; and funcsave c 
alias la "ls -la"; and funcsave la 
alias p "cd -"; and funcsave p 
alias pa "ps aux | grep"; and funcsave pa 
alias s "cd .."; and funcsave s 
alias x "exit"; and funcsave x

(and some more involved ones which I might discuss in a later post — just note that oneliners are usually better defined as an alias rather than a script)

...install autojump and virtualfish and load them in ~/.config/fish/config.fish:

set -g -x EDITOR vim                               
set -g -x BROWSER chromium

if test -e /etc/profle.d/autojump.fish
    . /etc/profile.d/autojump.fish
end

set -xU WORKON_HOME ~/.virtualenvs
eval (python -m virtualfish compat_aliases auto_activation)

...select a proper prompt (I usually use RobyRussell) by issuing

fish_config

...and modifying this prompt to also indicate a python virtualenv as detailed here.

Here's an example for navigating the file system via the autojump feature including directories under revison control and containing a python virtualenv.

Note how the virtualenv activated itself automagically thanks to the 'auto_activation' option in fish's config above. ☺ And: the config above is really the entire configuration file. 559 bytes!

bash

To get a similar result for the bash requires significantly more effort. As root, I never use the fish but always the bash, and I thus need to spend time to configure this shell as well. In particular, I expect the shell to autocomplete systemctl calls such as

systemctl status pos

with

systemctl status postfix.service

This functionality requires installation of the bash-completion package.

Some of the history features which fish offers out-of-the-box have to be activated for the bash, and I've explained how to do that previously. Other than that, I edited my .bashrc to include important features of its history, and the following lines at the end:

source /etc/profile.d/autojump.sh
export WORKON_HOME=~/.virtualenvs
source /usr/bin/virtualenvwrapper.sh

As for the prompt, I mostly use the various ones made available by bash-it, a bash framework similar to oh-my-zsh for the zsh, or wahoo for the fish. Since I keep both the aliases and the prompt separate from the main configuration file, we can compare sizes: my .bashrc weighs a rather hefty 1627 bytes.

Here's an example with the tylenol theme:

zsh

Never really used it for longer times, as I never really saw a significant advantage compared to a properly configured bash (or even a fish out-of-the-box). That's more my fault than that of the zsh. In nay case, if I feel using the zsh, I rely on the oh-my-zsh framework. Here's an example using the dstufft theme:

Terminal

The shell is one thing, but the other one is the terminal we are using to interact with it. I typically use the terminal emulators appropriate for a given environment: konsole within kde, gnome-terminal in gnome, and urxvt in wmii. For the bastardized openbox environments on my desktops and notebooks, I employ lxterminal, xfce4-terminal, terminator, and guake.

The by far most obvious characteristics of the terminal is its font. I still prefer terminus for low display resolutions (such as 1366x768 in the screenshots above), but I switched to antialiased fonts for higher ones.