rlwrap
1.1、rlwrap简介
short for:readline wrapper
是什么 ?:a small utility that uses the GNU readline to allow the editing of keyboard input for any command.
开发语言:C
源码仓库:https://github.com/hanslub42/rlwrap
1.2、通过包管理器安装rlwrap
操作系统包管理器安装命令
macOSHomeBrewbrew install rlwrap
GNU/LinuxLinuxBrewbrew install rlwrap
aptsudo apt-get install -y rlwrap
CentOSyumsudo yum install -y rlwrap
dnfsudo dnf install -y rlwrap
openSUSEzyppersudo zypper install -y rlwrap
Alpine Linuxapksudo apk add rlwrap

Arch Linux

ArcoLinux

Manjaro Linux

pacmansudo pacman -Syyu --noconfirm
sudo pacman -S    --noconfirm rlwrap
Gentoo LinuxPortagesudo emerge rlwrap
1.3、通过编译源码安装rlwrap

step1、安装依赖

下载时cURL
解压时targzip
编译时POSIX shGNU CoreUtilsGNU makeGCC ( gcc )   | LLVM / Clang
运行时
  • glibc ( libc.sold-linux-x86-64.so )
  • readline ( libreadline.so )

step2、使用curl命令下载rlwrap源码包 (

curl -LO https://github.com/hanslub42/rlwrap/releases/download/v0.43/rlwrap-0.43.tar.gz

step3、使用tar解压rlwrap源码包

tar vxf rlwrap-0.43.tar.gz

step4、进入rlwrap-0.43目录

cd rlwrap-0.43

step5、查看rlwrap-0.43目录中的内容

step6、创建构建目录,并进入该目录

mkdir build && cd build

step7、使用../configure配置编译参数

../configure是一个可执行的POSIX sh脚本,用它 配置后会产生GNU make的配置文件Makefile

../configure的使用格式如下:

./configure [option]... [VAR=VALUE]...
option说明
--help    | -h查看../configure的使用帮助
--version | -V查看../configure是哪个版本的autoconf生成的
--quiet   | -q | --silent不输出checking...这些信息
--prefix=DIR指定安装目录。默认是/usr/local/
--host=HOST
设置目标程序运行的CPU平台
一般不需要设置,除非你想要交叉编译
默认与与宿主机一样
--enable-FEATURE[=yes|no]
yes:开启FEATURE
no :关闭FEATURE
--enable-dependency-tracking[=yes|no]是否开启依赖追踪
--enable-option-checking[=yes|no]是否检查有无不认识的--enable-FEATURE--with-PACKAGE参数
--enable-silent-rules[=yes|no]
yes相当于make V=0
no 相当于make V=1
--enable-debug[=yes|no]
调试选项。
yes相当于CPPFLAGS="-DDENUG"
no 相当于CPPFLAGS="-DNDENUG"
--enable-pedantic-ansi[=yes|no]是否给编译器设置-pedantic -ansi选项
--enable-homegrown-redisplay[=yes|no]
--enable-spy-on-readline[=yes|no]
--enable-proc-mountpoint[=DIR]

注意:

enable-FEATURE对应的选项,还有disable-FEATUREdisable-FEATURE相当于enable-FEATURE=no

示例:

../configure --prefix=/usr

step8、使用GNU make进行编译

make [option]... [VAR=VALUE]... [TARGET]...
VARVALUE示例说明
CCgcc |  clang指定C编译器
CFLAGS-O2 -v指定C编译器的参数
CPPcpp指定C预处理器
CPPFLAGS-I<includeDIR>指定C预处理器的参数
LDFLAGS-L<libDIR>指定C链接器的参数
LIBS-l<libName>指定C链接器要链接的库的名称

示例:

nproc() {
    if command -v nproc > /dev/null ; then
        command nproc
    elif command -v sysctl > /dev/null ; then
        sysctl -n machdep.cpu.thread_count
    elif test -f /proc/cpuinfo ; then
        grep -c processor /proc/cpuinfo
    else
        printf "%b" 4
    fi
}

make -j$(nproc) CFLAGS="-O2 -v"

step9、安装

sudo make install
1.4、rlwrap命令

rlwrap命令的使用格式如下:

rlwrap [option]... <COMMAND> [ARGUMENT]...

示例:

rlwrap -a -- -c -i -f ~/.rlwrap/sqlite3_completions sqlite3

-f FILE指定自动补全的关键字文件。这里是自动补全sqlite3 shell中的命令和SQL语句。

mkdir ~/.rlwrap
echo '.help' | sqlite3 | grep -o '^\.[a-z]* ' >> ~/.rlwrap/sqlite3_completions
echo 'ABORT ACTION ADD AFTER ALL ALTER ANALYZE AND AS ASC ATTACH AUTOINCREMENT BEFORE BEGIN BETWEEN BY CASCADE CASE CAST CHECK COLLATE COLUMN COMMIT CONFLICT CONSTRAINT CREATE CROSS CURRENT_DATE CURRENT_TIME CURRENT_TIMESTAMP DATABASE DEFAULT DEFERRABLE DEFERRED DELETE DESC DETACH DISTINCT DROP EACH ELSE END ESCAPE EXCEPT EXCLUSIVE EXISTS EXPLAIN FAIL FOR FOREIGN FROM FULL GLOB GROUP HAVING IF IGNORE IMMEDIATE IN INDEX INDEXED INITIALLY INNER INSERT INSTEAD INTERSECT INTO IS ISNULL JOIN KEY LEFT LIKE LIMIT MATCH NATURAL NO NOT NOTNULL NULL OF OFFSET ON OR ORDER OUTER PLAN PRAGMA PRIMARY QUERY RAISE RECURSIVE REFERENCES REGEXP REINDEX RELEASE RENAME REPLACE RESTRICT RIGHT ROLLBACK ROW SAVEPOINT SELECT SET TABLE TEMP TEMPORARY THEN TO TRANSACTION TRIGGER UNION UNIQUE UPDATE USING VACUUM VALUES VIEW VIRTUAL WHEN WHERE WITH WITHOUT' >> ~/.rlwrap/sqlite3_completions