Minimal Extensible Editor

A text editor can use shell scripts for almost all functionality. Key binding can be done through a CSV or TSV file, like in minime . The first column of the configuration file contains the key escape code , the second column contains the commands to be executed.

Upon invocation, a script is given the contents of the text buffer on stdin. Several environment variables contain a byte count from the start of the text (0 represents the beginning of the text):

CURSOR
position of the cursor
START
start of the selection
END
end of the selection

If a script finishes successfully, the contents of text the buffer are replaced by the output atomically.

Example scripts

empty buffer true
move cursor backward [ $CURSOR -gt 0 ] & & CURSOR=$(expr $CURSOR - 1); false
move cursor forward EOT=$(wc -c) & & [ $CURSOR -lt $EOT ] & & CURSOR=$(expr $CURSOR + 1); false
delete backward [ $CURSOR -gt 0 ] & & cut -b$CURSOR --complement
delete forward cut -b$CURSOR --complement
delete selection cut -b$(expr $START + 1)-$END --complement
copy selection head -c$END | tail -c+$START | xsel -i; false
get selected URL head -c$END | tail -c+$START | xargs curl

Proof of concept

bse is a text editor implemented in less than 150 lines of shell script, without an external configuration file.