Friday, April 01, 2016

tty Types

I have long ago given up on using anything other than GNU Screen as a terminal emulator.  If you're reading this I'm confident you know what both of those things are and why I would need them.  If not, then you work in a different UNIX-y world than I do.  See you next time.

Seriously, though, all of the other emulators I used to use were so fusty and full of so many eccentricities (when compared to everything else I use on a daily basis) that I nearly lost my mind when I realised I could just do this:

# screen /dev/ttyS0 115200

and like actual magic get something with a civilized scrollback buffer, keyboard-centric cut-and-paste from multiple buffers, split-screen, logging, all of the stuff I love about GNU Screen.

But man, there's been one persistent irritation remaining:

That drives me nuts.  If I dare start up vi on some file on one of these, then the terminal gets sufficiently mangled that I'm now reduced to an 80x24 window inside my ridiculously large xterm.  There's no need of that.

In ancient times, you used to be able to create a file named /etc/ttytype where you would create a mapping like this:

screen-256color ttyS0

And that would be interpreted by whatever getty variant you were using and set up your login environment sanely.  That's no longer the case in Debian (and probably no longer the case in most Linux systems today), so I've just been suffering with this until recently.

This is what I've come up with to work around the problem.

# echo <<eot&gt>~/.profile
> TERM=screen-256color
> export TERM
> eval `tset -s`   
> resize
# ^D

Then on my next login I get this:

Muuuuch better.

I have resize on most every system I use, so that works for me, but then in my digging around I found this on the Arch wiki:

rsz() {
 if [[ -t 0 && $# -eq 0 ]];then
  local IFS='[;' escape geometry x y
  print -n '\e7\e[r\e[999;999H\e[6n\e8'
  read -sd R escape geometry
  x=${geometry##*;} y=${geometry%%;*}
  if [[ ${COLUMNS} -eq ${x} && ${LINES} -eq ${y} ]];then
   print "${TERM} ${x}x${y}"
   print "${COLUMNS}x${LINES} -> ${x}x${y}"
   stty cols ${x} rows ${y}
  [[ -n ${commands[repo-elephant]} ]] && repo-elephant || print 'Usage: rsz'  ## Easter egg here :)

I've not used it, but it looks good.  I probably will try it next time I'm on a seriously limited system.

But this is one where I'd like some feedback.  If you've got this far you must have your own solution to this (or you've got a higher pain threshold than I do), so what've you done to solve this problem?