Home

Awesome

vtsh

vtsh is a mashup of a virtual terminal (vt) and a command interpreter a.k.a. shell (sh) for Unix-like operating systems such as Linux and OpenBSD. It could also be thought vtsh means vertical tabs of shells.

vtsh is also a text editor, but vtsh is created foremost for interacting with commands: the text editing facility come as a very useful side effect. Nevertheless, vtsh can be used as a text editor for all purposes.

In vtsh, the output of commands go to their own editable and viewable buffers, the output can be used for launching new commands and the output buffer can be used for interacting with the backend program in a linear or non-linear fashion. The buffers can also be saved to file, or the buffer contents can be redirected as input to other commands.

In other words, vtsh is like a command shell in Unix-like systems, but vtsh is implemented for the screen-based devices instead of paper teletype devices, this time using the advantages that screen-based devices offer, unlike the traditional line-based shells.

Screenshots

See the screenshot showing various features.

See also the animated screenshot showing vtsh running line-based editor from 1970s using vtsh's slave buffers and buffer redirection achieving cursor-addressable editing without code modifications to the original ed editor. It means even the venerable ed gains screen-based editing functionality when used through vtsh, even though editing in vtsh does not require the use of the ed editor.

Original inspiration

vtsh is an exercise in taking the Unix philosophy to the extreme in the footsteps of e.g. acme editor/user interface for programmers that was originally created for the Plan 9 operating system and its lesser known philosophical base described in A Minimal Global User Interface paper written by Rob Pike.

The inspiration for exploring similar avenues came to vtsh's author out of frustration independently and unaware of Rob Pike's efforts when the author was

Originally the thought of implementing vtsh came to the author after implementing a paper teletype device and figuring out how would one use such a device efficiently. It would be stupid to waste paper by re-running commands, and it would be difficult to find a particular output from a long, endless scrollback. The solution was: cutting useful outputs from the scrollback to small slips of paper that would be laid out on a table so that all useful pieces would be visible at the same time. The author wanted to do the same for a screen-based device as a solution to the frustration with traditional virtual terminals. This led to the development of cocowm, cocovt and vtsh.

The principal idea in vtsh is that it keeps each command's output in a separate buffer, alike to slips of paper, that can be independently arranged and scrolled as wished.

Furthermore, vtsh enables potential for more simplicity and user control for programmers and hackers-alike. When using vtsh as an user interface, it becomes a layer that frees the downstream programs from having to reimplement cursor addressable user interfaces, and as it does that, the user interface elements can be customized from a single place, thereby implementing some of the same ideas as originally described by Rob Pike.

In practice, when using vtsh, it means

Not having to care about representation or controls means simplicity and ease of development, as well as composability of unrelated programs, but it also means more user control by providing a single layer which can be used for customizing the representation and controls how ever the user wishes.

Sending input

In a perfect world all text-based software would be implemented in a non-interactive stateless request-response form where one request results in one response. That way we'd have the greatest simplicity and composability, but in reality we have many types of text-based software:

(Help wanted: give ideas how to describe these different types with better wordings...)

In addition to these, we have cursor-addressable text-based software such as mutt, emacs or vi but these will not be supported.

For supporting the different types of text-based software we need to both support sending input in a traditional typescript-way, i.e. inline input to the output stream (for asynchronous streams or for streams where the visibility of past commands is important for getting a picture of the current state) and for the other cases, we can use the command editor with or without slave buffers. The slave buffers help when we have some state but the state is not very interesting e.g. when we're running a long-lived ssh session to a remote host.

Slave buffers

Ctrl+S brings any number of slave buffers when an another slave buffer or an active command is focused.

Buffer redirection

When a command name ends with '<' the output buffer (a.k.a. typescript buffer) is sent as standard input to the command regardless of whether it was a slave buffer. The standard ^D (0x04) a.k.a. EOF is used as the delimeter.

(TODO: Buffer redirection works at the moment only with slave buffers.)

If the command name ends with '<.' then the input is delimited with '.' i.e. this is useful with e.g. 'ed'.

Examples

Redirect existing buffer contents to the 'cat' command which writes to '/tmp/foobar' file:

cat >/tmp/foobar<

Open 'README.md' file using 'ed', print the contents of lines 1-10 and then replace the same lines with the buffer contents thereby allowing cursor editing using 'ed' without code modifications to 'ed':

ed README.md
1,10p
1,10c<.

Files and directories

Opening files and directories is possible by prefixing command by a ":". When opening directories have "/" after it to signify it is a directory.

Change to a parent directory:

:../

Open a file:

:README.md

TODO

See also vtsh issues.

Known issues

See also vtsh issues.

Unique keyboard focus system

vtsh can be used without mouse, unlike acme, but vtsh has a unique way of how it can be used using keyboard. vtsh has a two-level focus system:

Toggling between the level is possible using Alt+Enter, or alternatively Esc.

Noteworthy deviations

From Emacs-like editors

From normal virtual terminals

Using with mouse

Default key bindings

Buffers

Editing

The bindings here are loosely-based on Emacs bindings, casual Emacs users should feel at home.

Search

Cut/paste and selections

Misc

Dependencies

The target is that it works on OpenBSD base system without requiring additional packages. The OpenBSD base system has a good balance of a standards compliant minimum installation that has just enough stuff installed so that programs like this can be compiled without needing to download external dependencies.

When compiling for other systems, you may need to install some random dependencies such as C compiler and standard header files.

Build and install to home directory

$ ./configure ~
$ make
$ make install

Customize colors and fonts

Take a look at color.enums and font.enums, modify and recompile.

vtsh supports both variable-width and fixed-width fonts (unlike xterm) and supports the fontconfig FcPattern syntax as well as the X Logical Font Description (XLFD).

You could try fonts such as:

These should be available in a modern X11 installation unless otherwise noted. Change sizes to taste. You could also have a look at X Terminal TrueType Fonts article written by Jamm!n.

(xrdb-compatible resources could be added later.)

See also