views:

308

answers:

3

In a comment in response to a shell question, user tinkertim said that it was easy to hack ksh to use the bash autocompletion library. I would like nothing better than to use bash autocompletion with AT&T ksh93. How can this be done?

ksh93 has a new release several times a year, so I am looking for a solution that does not involve modifying the source code. ksh93 can link new C modules dynamically and also is highly programmable (I run a ksh function at every keystroke), so modifying the source should not really be necessary.

Note: I am not talking about filename autocompletion, which is easy to do in ksh. I'm talking about all the other yummy autocompletion stuff that bash does, like autocompletion options for nmh commands or autocompleting Mercurial commmands. Stuff like that.

A: 

There is the Readline wrapper, rlwrap. Maybe you already have a software package for your system.

It sits above the standard input of a program you start, it's configurable and a bit programmable, it keeps a history.

I usually use it for stuff like Oracle SQL*Plus.

It may or may not be the tool you're searching for, you have to check.

TheBonsai
rlwrap actually looks quite useful for other problems, but its autocompletion facilities are minimal.
Norman Ramsey
And it would collide with the input capabilities of KSH anyways, if there are some specials.
TheBonsai
A: 

I think one of the simplest ways I have found to do this (on a client's server where I have no access to change packages and whatnot) is to set the line editor to emacs set -o emacs then double-tap ESC (ESC-ESC).

This isn't the most effective auto-completion, but it's all I have here without doing some funky hacking of my .profile and possibly violate usage rules.

Sean
A: 

In addition to set -o emacs there is also set -o vi which activates the keyboard combo ESC-\ for filename completion. (The ESC enters command mode, the \ engages autocomplete to complete as much of the filename as it can.) set -o vi also of course enables your command line for vi-style editing with its two modes of command-mode and insert-mode.

I concede this doesn't answer your original question of emulating bash-style autocompletion in ksh, but at least you are aware if you were not before aware of another way to engage ksh's build in autocomplete.

I also noticed another thread here with some related ksh autocomplete information, including ESC-= to get list of choices: link text

Bernard Assaf
*Filename* autocompletion is no problem in ksh. It's all the other autocompletion stuff I'd like, such as the ability to autocomplete `cvs` commands and suchlike.
Norman Ramsey