cool utility: rlwrap
Sep 15th, 2007
I came across rlwrap, while searching on how to enable history for sqlplus on linux. It turns out that sqlplus does not support command line history on linux. This fact itself I found surprising. I was sure all this time that I had some configuration problem with sqlplus on linux, but it turns out that sqlplus simply doesn’t support command line history on linux. I found rlwrap to be an excellent option for providing command line history for tools such as sqlplus. It not only supports the up arrow for history, but also supports the backwards search option using Ctrl+r. Additionally, the tool support completion suggestions either based upon the names of files or using a list of words found in a file. While using rlwrap with sqlplus, for example, I can create a file with a list of the table names I use, and then when by pressing tab receive completion suggestions (based on typed prefix) for possible table names.
rlwrap is very easy to use. You simply prefix the command you want to use with rlwrap. For example: rlwrap sqlplus
I was very impressed with this tool, so I also installed rlwrap on cygwin. For some reason on cygwin I needed to set the environment variable: RLWRAP_HOME to get the command history to work. I simply set this variable to point to a directory named .rlwrap in my home directory and then everything worked great.
I really liked the completion option via a file with completion suggestions. What I did find missing was a way to add context sensitivity to these suggestions. Adding an easy (and the emphasize here is on easy) option to customize the suggestions based on the context of the line would be a big functional boost for me. Possible options for specifying such context sensitivity might be via regular expression matching or executing some kind of script action. Bash has support for “Programmable Completion” and it might be possible to take some concepts from there.