App-optex
view release on metacpan or search on metacpan
unsupported options.
% date -Iseconds
Common configuration is stored in `~/.optex.d/default.rc` file, and
those rules are applied to all commands executed through **optex**.
Actually, `--iso-8601` option can be defined simpler as this:
option --iso-8601 -I$<shift>
This works fine almost always, but fails with sole `--iso-8601`
option preceding other option like this:
% date --iso-8601 -u
## COMMAND ALIASES
Command aliases can be set in the configuration file like this:
[alias]
pgrep = [ "greple", "-Mperl", "--code" ]
Alias name is used to find rc file and module directory. In the above
example, `~/.optex.d/pgrep.rc` and `~/.optex.d/pgrep/` will be
referred.
Read ["CONFIGURATION FILE"](#configuration-file) section.
## MACROS
Complex string can be composed using macro `define`. Next example is
an awk script to count vowels in the text, to be declared in file
`~/.optex.d/awk.rc`.
define __delete__ /[bcdfgkmnpsrtvwyz]e( |$)/
define __match__ /ey|y[aeiou]*|[aeiou]+/
define __count_vowels__ <<EOS
{
s = tolower($0);
gsub(__delete__, " ", s);
for (count=0; match(s, __match__); count++) {
s=substr(s, RSTART + RLENGTH);
}
print count " " $0;
}
EOS
option --vowels __count_vowels__
This can be used like this:
% awk --vowels /usr/share/dict/words
When setting complex option, `expand` directive is useful. `expand`
works almost same as `option`, but effective only within the file
scope, and not available for command line option.
expand repository ( -name .git -o -name .svn -o -name RCS )
expand no_dots ! -name .*
expand no_version ! -name *,v
expand no_backup ! -name *~
expand no_image ! -iname *.jpg ! -iname *.jpeg \
! -iname *.gif ! -iname *.png
expand no_archive ! -iname *.tar ! -iname *.tbz ! -iname *.tgz
expand no_pdf ! -iname *.pdf
option --clean \
repository -prune -o \
-type f \
no_dots \
no_version no_backup \
no_image \
no_archive \
no_pdf
% find . --clean -print
## MODULES
**optex** also supports module extension. In the example of `date`,
module file is found at `~/.optex.d/date/` directory. If default
module, `~/.optex.d/date/default.pm` exists, it is loaded
automatically on every execution.
This is a normal Perl module, so package declaration and the final
true value is necessary. Between them, you can put any kind of Perl
code. For example, next program set environment variable `LANG` to
`C` before executing `date` command.
package default;
$ENV{LANG} = 'C';
1;
% /bin/date
2017å¹´ 10æ22æ¥ æ¥ææ¥ 18æ00å00ç§ JST
% date
Sun Oct 22 18:00:00 JST 2017
Other modules are loaded using `-M` option. Unlike other options,
`-M` have to be placed at the beginning of argument list. Module
files in `~/.optex.d/date/` directory are used only for `date`
command. If the module is placed on `~/.optex.d/` directory, it can
be used from all commands.
If you want use `-Mes` module, make a file `~/.optex.d/es.pm` with
following content.
package es;
$ENV{LANG} = 'es_ES';
1;
% date -Mes
domingo, 22 de octubre de 2017, 18:00:00 JST
When the specified module was not found in library path, **optex**
ignores the option and stops argument processing immediately. Ignored
options are passed through to the target command.
Module is also used with subroutine call. Suppose
`~/.optex.d/env.pm` module look like:
package env;
sub setenv {
while (($a, $b) = splice @_, 0, 2) {
$ENV{$a} = $b;
}
}
1;
Then it can be used in more generic fashion. In the next example,
( run in 0.518 second using v1.01-cache-2.11-cpan-cd2fffc590a )