How to use the left and right arrow keys in the tclsh interactive shell (Ubuntu 14.04)?

Viewed 2847

Why can't I use the left and right arrow keys (actually, the same goes for the up and down keys as well) to move about the line I'm currently on in the tclsh interactive shell? If I try to press either one, I get a bunch of abracadabra instead of moving back and forth. This is not all that convenient when, for example, you make a typo, but you can't move the cursor back to change it. You have to use the backspace key to erase all the stuff that you've typed after the place where the typo is located thereby destroying all your work. Is it possible to fix this, quite frankly, buggy behaviour?

enter image description here

2 Answers

You can use the the generic rlwrap as suggested by schlenk, or you can use tclreadline:

Install tclreadline (e.g. with the following command for debian/ubuntu):

sudo apt install tclreadline

Automatically load it by adding it to your ~/.tclshrc:

if {$tcl_interactive} {
    package require tclreadline 
    ::tclreadline::Loop
}

Using tclreadline does not only provide the basic editing features but also includes tab completion, which rlwrap can't do due to it's generic nature.

Related