I am using rlwrap to colorize prompt in asterisk CLI:rlwrap -s 99999 -a -pRED /usr/sbin/asterisk -rI read in man rlwrap that I can also use rlwrap -z pipetoto pipe output through a colorizer. I have grc colorizer which works like this:cat foo | grcat <conf_file>The above examples colorizes foo using the rules from <conf_file>. How can I use rlwrap -z pipeto to colorize output from rlwrap through grcat ?
rlwrap -z pipeto: piping output through pagers
command line;pipe;colors;grc
pipetoUnfortunately, rlwrap's built-in filter pipeto does not filter output in the way you desire. I find the documentation rather misleading, but what it does is if you run rlwrap -z pipeto some-shell, then, within the interaction:if you type commands without any pipe sign (|), those are passed verbatim to some-shell and then the output of that is simply printed;if you type command | filter, then command is passed to some-shell to interpret, and the output of that is piped through filter before being printed (where filter is any command you could run from the command line in your Unix shell).So the good news is you could get the behavior you are looking of, kindof, sortof, by running rlwrap -z pipeto asterisk and then remembering to append | grc to each command you want to pass to asterisk. But that would not be very convenient, would it? Hence outfilter.outfilterI suggest creating the following rlwrap filter script:#! /usr/bin/perluse lib ($ENV{RLWRAP_FILTERDIR} or .);use RlwrapFilter;use strict;my $filter = new RlwrapFilter;my $name = $filter->name;my $filter_command = join ' ', @ARGV;$filter->help_text(Usage: rlwrap -z '$name <filter-command>' <command>\n                   . Filter <command> output through <filter-command>);$filter->output_handler(sub {});$filter->prompt_handler(\&prompt);$filter->run;sub prompt {    my $prompt = shift;    my $output = $filter->cumulative_output;    $output =~ s/\r//g;    open (PIPE, | $filter_command)        or die Failed to create pipe: $!;    print PIPE $output;    close PIPE;    return $prompt;}Save it as outfilter, make it executable, and then run rlwrap -z './outfilter <coloring-filter>' shell. I tried with:rlwrap -z './outfilter ccze -A' goshwhich nicely colors Gauche's output. In your case, that would become something like:rlwrap -z './outfilter grcat grcat-config' asteriskIf you like the filter and want to be able to run it without having to specify its path, you could move it alongside the builtin filters (on my system, that's in directory /usr/share/rlwrap/filters).Note that the filter as written is probably inefficient (it spawns a new copy of the coloring filter for each interaction with the command shell, because that's the shortest way I could find to have it flush its buffers) and fragile, but if the shell you are interacting with doesn't do any black magic of its own, it should work.