A Solution for tclsh Editing Woes

The Problem

People who runs tclsh under Windows can use the up arrow, among other keys, to recall last commands issued. However, on the Mac and Linux environments, the up arrow only gives them ^[[A, which make for a frustrating experience. How do we get the editing capabilities that Windows users enjoy?

The Solution

One of the solution which I like is to use tkcon, tk-based Tcl shell, which offer excellent command line editing, among other features. On my Mac, tkcon is in /usr/bin/tkcon, the the location may vary. To determine if tkcon is installed in your system, issue the following command:

which tkcon

If you don’t see any output, you will need to install it. On the Mac, head to http://tkcon.sourceforge.net/, download it and follow the instruction to install. On Linux, the instructions are different, depending on which distribution so you should search for it.

Once installed, you can start tkcon using the following command:

tkcon &

The ampersand will launch tkcon in the background and return control immediately to the terminal. On my Mac, tkcon pops under other windows, so after launching, I have to task switch to it using the command + tab key combination. I hope you enjoy using tkcon as I do.

6 thoughts on “A Solution for tclsh Editing Woes

  1. Pingback: How to Fix tclsh Line Editing Problem « Hai’s Blog

  2. Anonymous

    There is a kind of “wrapper” called “rlfe” which can solve that issue. I’ve wirtten an alias like “alias tclsh=’rlfe tclsh'” so when I type “tclsh” it adds silently the wrapping.
    I know there’s been a long time since your post, but I hope this can help some other lost soul suffering from readline support under tclsh. Greets.

  3. Michael Klement

    Thanks for pointing us to `tkcon` – the advantage that it offers over other makeshift solutions such as `rlfe tclsh` and `rlwrap tclsh` is that you get _command completion_.

    To fix the annoyance when invoking `tkcon`, you can try the following alias `alias tkc=”(tkcon &) && osascript <<> ~/.tkconrc`

    One annoyance is that the window placement and size isn’t remembered between sessions, and the defaults are awkward. If you know how to fix this, please let us know.

  4. Michael Klement

    Thanks for pointing us to `tkcon` – the advantage that it offers over other makeshift solutions such as `rlfe tclsh` and `rlwrap tclsh` is that you get _command completion_.

    To fix the annoyance when invoking `tkcon`, you can try the following alias:

    alias tkc="(tkcon &) && osascript <<<\$'repeat while true\n  delay 0.1\n  if application \"Wish\" is running then\n    try\n      activate application \"Wish\"\n      return\n    end try\n  end if\nend repeat'"`.

    Clunky, but it works: launches `tkcon` without blocking the terminal and activates the new window.

    The default font size is small, and you cannot change it via the GUI, but it can be controlled via (see http://tkcon.sourceforge.net/docs/start.html):
    * The `-font` command-line option; e.g.:

    tkcon -font "Courier 18"

    * tkcon’s resource file, `~/.tkconrc`; e.g.:

    echo "tkcon font Courier 14;" >> ~/.tkconrc`

    One annoyance is that the window placement and size isn’t remembered between sessions, and the defaults are awkward. If you know how to fix this, please let us know.

  5. Hai Post author

    On my mac, my ~/.tkconrc looks like this:

    set ::tkcon::OPT(rows) 40
    set ::tkcon::COLOR(bg) ivory
    set ::tkcon::OPT(font) “{Liberation Mono} 12”

    At least, I have control over the number of rows. I don’t know how to control the window position.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s