Benjamin Sago / ogham / cairnrefinery / etc…

Technical notes Customise what htop displays

htop has a fairly detailed customisation interface available by hitting F2. You can change the colour theme, pick which columns are shown in the table, choose which meters are shown on top, and plenty of other things. The UI is a little clunky, requiring you to use the F keys — something you don’t see often in TUI programs — but it is full-featured.

I find that by hiding some of the parts I never want to see, and tweaking the UI slightly, htop becomes a smidge nicer to use.

A screenshot of htop.

Changing the meters

I like to hide the ‘Uptime’ meter from the top of the screen. If I want to see it, I can just run uptime, and it means the table of processes can be one row taller which I think you’ll agree is very important.

On the other hand, I also put a blank row between the CPU meters and the other ones by inserting a ‘Blank’ meter on both sides. This makes it look better to me, even if it means that extra table row is gone again.

Changing the table columns

I personally only ever use the ‘PID’, ‘User’, ‘State’, ‘CPU%’, ‘MEM%’, and ‘Command’ columns, so I’ve hidden all the ones apart from those. This makes the table easier to scan as I’m not flooded with information when I look at it.

Checking the configuration

Unlike other traditional Unix command-line programs, htop’s configuration file is more like a state file. Instead of htop reading this file on startup and then leaving it alone, htop will update this file while it’s running if you use its configuration interface.

If you view it in your text editor, you’ll see this warning at the top:

Beware! This file is rewritten by htop when settings are changed in the interface.
The parser is also very primitive, and not human-friendly.

This means that while you’re probably going to be fine putting your htoprc file in version control, the file can still be modified through htop itself.

So what did I do? Because I’m already using Specsheet for so many other things, I added five more checks to make sure the contents of the config file are what I expect them to be:

name = "Configure htop left meters"
path = '~/.config/htop/htoprc'
contents = { regex = "left_meters=LeftCPUs2 Blank Memory Swap" }

name = "Configure htop left meter modes"
path = '~/.config/htop/htoprc'
contents = { regex = "left_meter_modes=1 2 1 1" }  # Bar, Blank, Bar, Bar

name = "Configure htop right meters"
path = '~/.config/htop/htoprc'
contents = { regex = "right_meters=RightCPUs2 Blank Tasks LoadAverage" }

name = "Configure htop right meter modes"
path = '~/.config/htop/htoprc'
contents = { regex = "right_meter_modes=1 2 2 2" }  # Bar, Blank, Text, Text

name = "Remove some columns from htop"
path = '~/.config/htop/htoprc'
contents = { regex = "fields=0 48 46 47 1" }  # PID, User, CPU, Mem, Command