Post

shell

This doc contains my accumulated knowledge about console, terminal and shell. I, together with many of you, do not spend dedicated time to learning these concepts, but instead keep accumulating the knowledge from time to time.

VT100

VT100 is a popular video terminal. I learnt a lot about it when I was following this guide to build an terminal editor from scratch. Some basic knowledge about VT100 helps you understand your .bashrc and .inputrc.

Its official doc is the place you can find all you need to know. For example, Control Sequences section shows that ESC[ is the control sequence introducer. Cursor Control section shows that ESC[A is the code for Arrow UP.

SGR

SGR - Select Graphic Rendition, as name suggests, controls graphic rendition. The control sequence has format ESC [ Ps ; . . . ; Ps m. VT100 doc does not provide all available selective parameters. We can go to wiki to find more.

The most useful case is to set color. From the table in the wiki link above, 31 represents foreground color red. 41 represents background color red, so ESC[31,41m means sets both foreground and background to red. Yeah, sure. Nobody will set the foreground color the same as background color :). Also, it says 0 resets the color. So ESC[m or ESC[0m resets the color.

Bash

  • Bash test framework: https://github.com/sstephenson/bats

Zsh

Parameter expansion

Zsh does not do word splitting. For example, this is what happens in zsh

1
2
3
$ export DYDB="aws dynamodb --endpoint-url http://localhost:8081"
$ $DYDB list-tables
zsh: no such file or directory: aws dynamodb --endpoint-url http://localhost:8081

There are two ways to make it compatible with bash:

  1. Use ${=variable}
  2. setopt shwordsplit

See zsh FAQ.

ZLE

ZLE is the line editor in Zsh. readline is the line editor in bash. so .inputrc in bash cannot be used in zsh. We need to use bindkey builtin to define these key bindings.

This post is licensed under CC BY 4.0 by the author.