bash script with own command line interpreter
update: i'm changing this post to a question, i really need help to properly implement TAB completion to make this work (it's part of a bigger framework). If anyone has info on how to get readline+complete/compgen to work when using "read -e", please post it!!!
Hello, this is a working template for an embedded command interpreter in a bash script. Given the scarce material i've seen on this i'm posting as a time saver for everyone.
It needs bash 4 with readline to work properly. Has command line edition, history and tab completion (provided by readline).
It also has automatic listing and validation of user commands based on the functions defined. If you want a function to NOT be accesible to the user, just use a "_" as the first character of its name (of course, this can be altered as needed).
i invite you to use/expand/comment etc.
Forgot to mention that the technique to get TAB completion is pulled from another LQ thread, thank you!
Anyway, i was hoping to get completion to work with the standard complete/compgen builtins instead of this history hack, but i couldn't for the life of me get those to work in the script whatsoever. I'd very,very much like to hear something about this working, as AFAICS it's truly an ugly part.
In this other LQ thread "complete" is reported as working, though it didn't worked for me.
The other bit i'd like to get some help about is this command substitution:
As detailed in this sister thread, programmable completion in read is disabled in the bash code by the maintainer.
I have contacted the maintainer of Bash, and been toold that this use case (presenting commands to the end user for completion) is the only one presented for programmable completion in the context of read, and it isn't considered compelling enough to worth the effort of implementing it.
This answer left me highly unsatisfied. I do not concord at all with that view, in fact i think that since you have a functionality that is clearly oriented to provide CLI implementations inside bash scripts, it well worths the effort to have it complete.
|All times are GMT -5. The time now is 06:40 PM.|