How can I program ksh93 to use bash autocompletion?

帅比萌擦擦* 提交于 2019-12-22 09:59:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!