ed is considered the modern grandfather of text editors for unix systems. It is interesting because of how it influenced “more” modern text editors and programs like vi, sed, and vim, but also in how one interacts with it.
ed’s interface works line-by-line as it needed to work on dumb terminals. You can think of dumb terminals as glorified printers. You could type text and it would be printed out, but the screen would not update portions of the screen separately.
This seems fairly limiting and to be honest the features of ed are pretty spartan. You can’t scroll. You can’t select areas with a mouse. No syntax highlighting. No editing text inline. No modern comforts like tab completion.
However ed has a couple benefits. Its line-by-line interface make editing files over high latency connections easier (try
ssh user@host ed
sometime) and it also lends itself well to scripting.
#a simple todo application using ed
Modern web frameworks like to show how useful they are by showing how easy it is to write a todo application in them. I’d like to show you below how easy it is to do something like this using ed and some bash.
#!/bin/bash
TODOFILE=~/.plan
case "$1" in
add)
printf '%s\n' a "$2 []" . w | ed -s $TODOFILE
;;
delete)
printf '%s\n' "$2d" w | ed -s $TODOFILE
;;
complete)
printf '%s\n' "$2s/\\[\\]/[x]/" w | ed -s $TODOFILE
;;
*)
cat -n $TODOFILE
esac
The printf
statements pipe commands separated by newlines into ed. They show examples of appending, deleting, and
updating in ed. For an indepth resource on scripting with ed, take a look here http://wiki.bash-hackers.org/howto/edit-ed.
An example of using the application.
[trengrj@home ~]$ todo add "write this blog post"
[trengrj@home ~]$ todo add "add colours to todo"
[trengrj@home ~]$ todo
1 write this blog post []
2 add colours to todo []
[trengrj@home ~]$ todo complete 1
[trengrj@home ~]$ todo
1 write this blog post [x]
2 add colours to todo []
[trengrj@home ~]$ todo delete 1
[trengrj@home ~]$ todo
1 add colours to todo []
[trengrj@home ~]$