Many things for not many people

Linux terminal tomfoolery

Published on: by David Jolley

Updated on: • 3 min read

Recently, I've been playing about with having Linux installed as the only operating system on my laptop. This has caused a few issues having come from a windows background although I've used Linux as a server operating system for a number of years (I first used Linux at version 0.11, and I still have the Yggdrasil install 5.25" floppy disk!).

Anyway, that's not what this post is about.

Linux's desktop has graphical terminal emulators. Not emulator, emulators (plural).

Each terminal emulator has its own behaviours and quirks, so there is - of course - a method by which the terminal emulator can tell the running program what features that particular terminal emulator supports/has. This is all very well for local desktop use, I've installed Ghostty as my terminal of choice (it supports all manner of nice things, including font ligatures and sixels, amongst other super-whizzo features).

So, I have Ghostty installed locally, and this works remarkably well whilst I am running programs on the local computer. But, as soon as I SSH into a remote system (say a headless server, such as the machine you're reading this from) and where that remote system doesn't have ghostty installed, the output of terminal-aware programs will start to stop working in various and interesting ways. Most notably, less will start to display warnings such as "WARNING: terminal is not fully functional" and other programs my emit similar such helpful aspertions.

This can - and has been, for more years than I care to mention - "fixed" by setting TERM=xterm for that session. Either by adding it to the .bashrc or actually typing it in manually (until I get bored, then I edit the startup file). But this will break in other subtle ways, for example when I manage to find a terminal emulator which doesn't emulate (enough of) xterm's behaviour.

So, today, I thought there must be a better way of doing this, and it turns out there is.

Remember, I said there was a mechanism by which the terminal decsribes its behaviours and supported features? That's called terminfo (RIP termcap), and it turns out that you can take the terminfo database entry from one system to another and having done so, the system onto which terminfo entry has been added behaves as if it knows about that terminal.

So, on my headless server that doesn't have a graphics card (let alone a graphics driver which will be able to support Ghostty's requirements), the system now behaves as if Ghostty is installed on the server and can be used. It's basically magic, but command line (as if there isn't already enough command line magic).

Anyway, you want to know the good stuff. How do you achieve this magic feat?

infocmp -x | ssh dave@apollo.lucien.me.uk tic -x -

That's it. You'll have to substitute your own username and server name in that incantation, and obviously you'll need to have ssh setup to automatically offer the correct credentials for that user to the server. But other than that, this will take the terminal info for the terminal in which you type that command, and pass it into the terminal information compiler on the other server, and then from that day hence, your terminal that you're using on your local machine will be "known about" on the server, and programs run there will no longer claim you have a broken terminal.

As has been pointed out to me, this requires tic to be installed on the remote system. For most linux servers, this is likely going to be the case. But for some cut-down (space constrained) embedded systems, this isn't always going to be the case. If you don't have tic on the remote system, you're back to the TERM=xterm(-256color) invocation (or set in your .ssh/config). Sorry...