Tag Archives: shells

Shells: ksh Tab Completion

If you are using the public domain version of the Korn Shell (pdksh), you can add the following line to your .kshrc and (providing ENV is set), you will have tab completion in vi mode:

You can see which shell options are currently set by running:

Please note, vi-tabcomplete is an option within the public domain Korn Shell only, and will not work with the “standard” ksh provided by many OS’s. In this case, you’ll have to make do with Esc-\ for filename completion.

Shells: How to Respond to a Single Keystroke Within a Script

If you are using a newer Bourne-compatible shell such as (pd)ksh or bash, and have a modern terminal, you can take advantage of the -icanon stty mode to good effect. This mode allows your scripts to respond to a single keystroke rather than requiring the user to hit “return” after entering a character. This is useful for the familiar “Press any key to continue … ” type messages, but can also be used to provide control of programs.

Ensure that you restore your old stty settings before exiting. This is probably best achieved by using traps. The following script demostrates these concepts well, and gives the foundations of a Minesweeper-style grid, cursors, and cell-marking.

Shells: Using vi-mode Line Editing in tcsh

Just a quick one. If you think emacs is a bunch of crap (like me), you’ll hate the way that tcsh defaults to using this Meta-key-ridden abomination for line editing. Let’s enable vi-mode line editing:

Ahhh, that’s better.

To make this persistent, just add it to ~/.cshrc_local:

Job done. Better yet, don’t use tcsh!