benjamin.computer

Making your terminals a bit nicer

23-04-2020

If you spend a lot of time in your terminal you might, if you are like me, get a little confused as to where you are. I suppose user-interface folks have looked it this quite a bit but I haven't. Recently, a chap asked me how my terminal displayed a cool ubuntu image and I figured that there are folks out there unaware of programs like figlet, neofetch and powerline, just as I was. Well, I figure I can do my bit and talk about what I do in my terminal to make things a tad nicer. I'm sure there are many more tips and tools out there but here are the ones I've played with thus far.

powerline
Powerline with the current git branch shown.

One thing I really wanted to do was colour each terminal differently. Sometime ago, I typed in:

sudo shutdown -h now

.. only this was on my server box! Yup! An easy mistake to make if you rush thing. Since then I've wanted colour cues for each different box. Enter Powerline.

powerline
Powerline with the current git branch shown, but on the right this time, and with different colours for the different machine.

Powerline seems to be quite popular and I'd never really noticed. It's a python program that provides a sort of status bar affair. I'm not overly familiar with it, but it seems to work in the terminal, in vim, in tmux and probably many other programs besides. It provides a considerable level of customisation. I found it initially difficult to get a different coloured prompt however, but with a bit of reading, I found the answer.

You need a file here:

~/.config/powerline/colorschemes/shell/proto.json

My file looks something like this:

{
    "name": "Proto colour",
"groups": {
    "user":                 { "fg": "white", "bg": "blue", "attr": ["bold"] },
    "superuser":            { "fg": "white", "bg": "red", "attr": ["bold"] },
    "hostname":             { "fg": "white", "bg": "darkgreen" },
"information:additional":     { "fg": "solarized:base2", "bg": "solarized:base01", "attrs": [] },
"information:regular":        { "fg": "solarized:base3", "bg": "solarized:base01", "attrs": ["bold"] },
"information:highlighted":    { "fg": "solarized:base3", "bg": "solarized:base01", "attrs": ["bold"]},
"information:priority":       { "fg": "solarized:base3", "bg": "solarized:yellow", "attrs": [] },
"warning:regular":            { "fg": "solarized:base3", "bg": "solarized:red", "attrs": [] },
"critical:failure":           { "fg": "solarized:base3", "bg": "solarized:red", "attrs": [] },
"critical:success":           { "fg": "solarized:base3", "bg": "solarized:green", "attrs": [] },
"background":                 { "fg": "solarized:base3", "bg": "solarized:base02", "attrs": [] },
"background:divider":         { "fg": "solarized:base1", "bg": "solarized:base02", "attrs": [] },
"user":                       { "fg": "solarized:base3", "bg": "solarized:blue", "attrs": ["bold"] },
"virtualenv":                 { "fg": "solarized:base3", "bg": "solarized:green", "attrs": [] },
"branch":                     { "fg": "solarized:base1", "bg": "solarized:base02", "attrs": [] },
"branch_dirty":               { "fg": "solarized:yellow", "bg": "solarized:base02", "attrs": [] },
"branch_clean":               { "fg": "solarized:base1", "bg": "solarized:base02", "attrs": [] },
"stash":                      "branch_dirty",
"email_alert_gradient":       { "fg": "solarized:base3", "bg": "yellow_orange_red", "attrs": [] },
"email_alert":                "warning:regular",
"cwd":                        "information:additional",
"cwd:current_folder":         "information:regular",
"cwd:divider":                { "fg": "solarized:base1", "bg": "solarized:base01", "attrs": [] },
"network_load":               { "fg": "solarized:base1", "bg": "solarized:base03", "attrs": [] },
"network_load:divider":       "network_load",
"network_load_gradient":      { "fg": "green_yellow_orange_red", "bg": "solarized:base03", "attrs": [] },
"network_load_sent_gradient": "network_load_gradient",
"network_load_recv_gradient": "network_load_gradient",
"environment":                { "fg": "solarized:base3", "bg": "solarized:green", "attrs": [] },
"attached_clients":           { "fg": "solarized:base3", "bg": "solarized:green", "attrs": [] },
"date":                       { "fg": "solarized:base1", "bg": "solarized:base02", "attrs": [] },
"time":                       { "fg": "solarized:base1", "bg": "solarized:base02", "attrs": ["bold"] },
"time:divider":               { "fg": "solarized:base1", "bg": "solarized:base02", "attrs": [] },
"system_load":                { "fg": "solarized:base1", "bg": "solarized:base03", "attrs": [] },
"weather_temp_gradient":      { "fg": "blue_red", "bg": "solarized:base03", "attrs": [] },
"weather":                    { "fg": "solarized:base1", "bg": "solarized:base03", "attrs": [] },
"uptime":                     { "fg": "solarized:base1", "bg": "solarized:base03", "attrs": [] }
}

}

Now I'm relying on some specific colours here. These need to exist in the following file:

 ~/.config/powerline/colors.json

Most installs of powerline include this file in the base install path. You can just copy it over. No doubt there is a lot more I can do but for now, this suffices.

I quite like the git branch feature. If you are inside a git repository, Powerline lists the branch right there in the bar. That's very handy when you are working on several branches of a particular project.

Serious computer in RED
Serious computer in RED

One annoying issue I've found relates to powerline fonts. I don't know which symbols powerline is using but some terminal emulators don't display the fonts correctly. putty is one of these sadly (and if folks have a better Windows option for me, do let me know). Sadly, another one is termite which I use quite a lot. Still haven't fixed it yet but I'll find the answer.

But what about that cool ascii test art font stuff? Well, this has been around for a while I believe. figlet is the program you are looking for, and it seems to be behind all of these ascii art text generators you can find on the web. There is another program called toilet which seems to offer a few more features. Either of these will generate some cool looking text.

I have a line to generate some cool text that looks like this...

cd /usr && toilet -f ./share/toilet/chunky.flf benjamin.computer --filter metal

Ideally I'd like a font that uses full blocks of colour, like the oldschool systems, as it's easier to read, but I've not found one yet. Maybe I need to make one?

Funky metal text
Funky metal text

But what about cool images in your terminal? Well then, neofetch is what you are after. It renders some nice text art for you, and you can use it as part of your login scren for a little extra joy.

I tend to use Ubuntu on my systems these days, though I'm still fond of Arch Linux. I know that Ubuntu uses a little program called motd to display it's message-of-the-day to the user. It has some extra little bits of information such as system status and the like. It's here where we can add some of our extra functions.

sudo vim /etc/update-motd.d/99-art

In this file, we can add some commands like...

#!/bin/zsh
neofetch

Now we can perform our little update...

sudo update-motd
sudo chmod +x /etc/update-motd.d/99-art
neofetch
NeoFetch doing what it does by default.

Getting one's terminal into order - making it a nice place to be - is one of these slightly annoying things that really pays off. I mean, if it's a place where you spend a lot of time, all these little changes add up. Makes me wonder what I've missed - there's probably even more I could do. Maybe I'll move into the world of custom keyboards next? I suspect that will be a lot more expensive!


benjamin.computer