问题
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.
回答1:
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.
回答2:
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.
回答3:
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
回答4:
Bind the tab key to call a bash script which uses the complete
builtin, so hitting tab in ksh93 actually runs bash to complete the text.
Consult http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html#Programmable-Completion-Builtins and http://www2.research.att.com/sw/download/man/man1/ksh.html (look for "Key Bindings") for details
回答5:
Try hitting ESC then '\' key. It should mimic the bash's autocomplete feature.
来源:https://stackoverflow.com/questions/942716/how-can-i-program-ksh93-to-use-bash-autocompletion