I want to do the Auto command completion in ksh for my product's CLI. For that I am using the key binding mechanism. But am stuck at following points.
-
I am not able to use .sh.edtext variable while KEYBD trap. As I know this variable contains Characters in the input buffer during a KEYBD trap. But in my script, this variable is always NULL. Can you please tell me How can I get the content of input buffer in my script.
-
If somehow I get the input buffer in my script then I have to compute the next possible completions based on the input buffer. Now:
A. If there is only completion.
In this case I have to append this to input buffer and put this new string on command prompt. How can I replace the content of command prompt with new string?
B. If there are more than 1 possible completion:-
I have to show all completions below the command prompt. This I can do with print command. Is there any other ways to do this.
I am using the following script for key bind:-
-------------------------------
typeset -A Keytable
trap 'eval "${Keytable[${.sh.edchar}]}" && VX_COMMAND=${.sh.edtext}' KEYBD
function keybind # key [action]
{
typeset key=$(print -f "%q" "$2")
case $# in
2) Keytable[$1]="$key"
;;
1) unset Keytable[$1]
;;
*) print -u2 "Usage: $0 key [action]"
return 2 # usage errors return 2 by default
;;
esac
}
export VX_COMMAND
keybind $'\Ew' function.sh #I want to bind Alt+w with function.sh and want to use input buffer in function.sh.
---------------------------------------
I didn't found these answers with GOOGLE.