util::filter - optex filter utility module
optex -Mutil::filter [ --if/--of/--ef command ] command
optex -Mutil::filter [ --if/--of/--ef &function ] command
optex -Mutil::filter [ --isub/--osub/--esub/--psub function ] command
Set input/output filter command for STDIN, STDOUT and STDERR. If the command start by &, module function is called instead.
&
Set filter function. These are shortcut for --if &function and such.
Set pre-fork filter function. This function is called before executing the target command process, and expected to return text data, that will be poured into target process's STDIN. This allows you to share information between pre-fork and output filter processes.
See App::optex::xform for actual use case.
Set color filter to filehandle. You can set color filter for STDERR like this:
--set-io-color STDERR=R
Use comma to set multiple filehandles at once.
--set-io-color STDIN=B,STDERR=R
Set default color to STDOUT and STDERR.
This module is a collection of sample utility functions for command optex.
Function can be called with option declaration. Parameters for the function are passed by name and value list: name=value. Value 1 is assigned for the name without value.
In this example,
optex -Mutil::function(debug,message=hello,count=3)
option debug has value 1, message has string "hello", and count also has string "3".
Primitive function to prepare input/output filter. All options are implemented by this function. Takes STDIN, STDOUT, STDERR, PREFORK as an io name and command or &function as a vaule.
STDIN
STDOUT
STDERR
PREFORK
mode function option --if &set(STDIN=$<shift>) option --isub &set(STDIN=&$<shift>)
Visualize control characters.
Make control and space characters visible.
By default, ESCAPE and NEWLINE is not touched. Other control characters and space are shown in unicode symbol. Tab character and following space is visualized in unicode mark.
When newline character is visualized, it is not deleted and shown with visible representation.
Name is tabstyle, all, or one of these: [ nul soh stx etx eot enq ack bel bs ht nl vt np cr so si dle dc1 dc2 dc3 dc4 nak syn etb can em sub esc fs gs rs us sp del ].
tabstyle
all
If the name is all, the value is set for all characters. Default is equivalent to:
visible(tabstyle=bar,all=s,esc=0,nl=0)
As for tabstyle, use anything defined in Text::ANSI::Fold.
If the flag is empty or 0, the character is displayed as is. If flag is c, it is shown in ^c format. Otherwise shown in unicode symbol.
c
^c
Reverse output.
Reverse characters in each line.
Shuffle lines.
Colorize text. IO is either of STDOUT or STDERR. Use comma to set both at a same time: STDOUT=C,STDERR=R.
STDOUT=C,STDERR=R
Splice lines.
Put timestamp on each line of output.
Format is interpreted by strftime function. Default format is "%T.%f" where %T is 24h style time %H:%M:%S, and %f is microsecond. %L means millisecond. %nN can be used to specify precision.
strftime
"%T.%f"
%T
%H:%M:%S
%f
%L
%nN
Gunzip standard input.
Gzip standard input.
Next command print ping command output with timestamp.
ping
optex -Mutil::filter --osub timestamp ping -c 10 localhost
Put next line in your ~/.optex.d/optex.rc. Then for any command executed by optex, standard error output will be shown in visible and colored. This is convenient or debug.
option default -Mutil::filter --io-color --esub visible
Above setting is not effective for command executed through symbolic link. You can set ~/.optex.d/default.rc, but it sometime calls unexpected behavior. This is a future issue.
App::optex::xform
https://qiita.com/kaz-utashiro/items/2df8c7fbd2fcb880cee6
To install App::optex, copy and paste the appropriate command in to your terminal.
cpanm
cpanm App::optex
CPAN shell
perl -MCPAN -e shell install App::optex
For more information on module installation, please visit the detailed CPAN module installation guide.