/dev/tty – about virtual consoles and shells

I spend most of my time using a computer in the terminal. This is my preferred method of working, if its editing or managing files doesn’t matter. There are obviously some things that just don’t belong into the terminal.

Viewing images using some obscure terminal extension is something I would personally never do, the terminal is good for many tasks but not all. For highly interactive or visual tasks I prefer to not use the terminal and use a program that does its job right. Reading pdf files is one of the things I prefer to not do in the terminal, there are exceptions. If its a badly formatted and/or short paper then its not problem. But losing all the typesetting features to the terminal does not really help while reading long texts.

There is another anti-pattern of terminal applications that seem to emulate GUI applications as much as possible in the terminal. I think alsamixer is a good and well known example for this. It prints useless volume bars and requires strange keybindings to switch between outputs to do a simple task like increasing or decreasing the volume.

shells

I use mksh(1) as my interactive shell or the system supplied ksh(1) on OpenBSD systems, to write scripts I use only POSIX shell features for portability. There are exceptions to this, but only if really necessary (at which point I really have to justify using shell in the first place).

plan9s rc(1) in clean and interesting, but there are some drawbacks like no substitutions and missing keywords like break and the if not instead of else. Another problem I have with rc(1) is that all variables are exported to the environment limiting the length of the value based on the operating system.

Prompt/PS1

My default PS1 prompt consists of the working directory name (or ~ of its the home directory), followed by @hostname if its a remote session to avoid running reboot on the wrong system. If the last command exited unsuccessful ?$? is added, a question mark followed by the exit status of the last command. The last character of my prompt shows if its a root or user shell and ends with # or $ respectively.

To easily spot the prompt I highlight the exit status in red and the last character in a different color.

~$ ssh pi
~@pi$ false
~@pi?1$ cd ~/repos
repos@pi$ ^D
Connection to pi closed.
~$