我读了版本 4 的清理规则。
% arara: clean: { extensions: [aux, bcl ] }
删除jobname.aux
和jobname.bcl
。
我想要一个规则“ cleanx.yaml
”(或一个移位器clean.yaml
),它可以删除所有具有命名扩展名的文件(*.aux 和 *.bcl)。
我该怎么做?我尝试concat('*')
了“base”,但是没有用。
!config
# Arara, the cool TeX automation tool
# Copyright (c) 2018, Paulo Roberto Massa Cereda
# All rights reserved.
#
# This rule is part of arara.
identifier: clean
name: Clean
authors:
- Marco Daniel
- Paulo Cereda
commands:
- name: Cleaning feature
command: >
@{
prefix = [];
if (isUnix()) {
prefix = [ 'rm', '-f' ];
}
else {
prefix = [ 'cmd', '/c', 'del' ];
}
if (extensions == '') {
if (getOriginalFile() == file) {
throwError('I cannot remove the main file reference.');
}
return getCommand(prefix, file);
}
else {
base = getBasename(file);
removals = [];
foreach(extension : extensions) {
if (base.concat('.').concat(extension) == getOriginalFile()) {
throwError('I cannot remove the main file reference.');
}
removals.add(getCommand(prefix, base.concat('.').concat(extension)));
}
return removals;
}
}
arguments:
- identifier: extensions
flag: >
@{
if (isList(parameters.extensions)) {
return parameters.extensions;
}
else {
throwError('I was expecting a list of extensions.');
}
}
答案1
这条新规则可能正好满足您的要求。但是,请务必小心使用它!
文件cleanx.yaml
:
!config
identifier: cleanx
name: CleanX
authors:
- Paulo Cereda
commands:
- name: Cleaning feature
command: >
@{
prefix = [];
if (isUnix()) {
prefix = [ 'rm', '-f' ];
}
else {
prefix = [ 'cmd', '/c', 'del' ];
}
if (extensions == '') {
if (getOriginalFile() == file) {
throwError('I cannot remove the main file reference.');
}
return getCommand(prefix, file);
}
else {
directory = getOriginalReference().getAbsoluteFile().getParent();
matches = listFilesByExtensions(directory, extensions, recursive);
removals = [];
foreach(match : matches) {
if (match.equals(getOriginalReference())) {
throwError('I cannot remove the main file reference.');
}
removals.add(getCommand(prefix, match));
}
return removals;
}
}
arguments:
- identifier: extensions
flag: >
@{
if (isList(parameters.extensions)) {
return parameters.extensions;
}
else {
throwError('I was expecting a list of extensions.');
}
}
- identifier: recursive
flag: >
@{
return isTrue(parameters.recursive);
}
default: false
注意:此规则使用辅助方法,该方法从原始引用的父目录中进行搜索。我还默认禁用了递归搜索。但是,可以使用指令参数启用它recursive
并提供自然布尔值,例如true
或yes
。
一个快速实验。我的文件头:
% arara: cleanx: { extensions: [ aux ] }
终端使用:
$ touch foo.aux bar.aux
$ arara -n test.tex
__ _ _ __ __ _ _ __ __ _
/ _` | '__/ _` | '__/ _` |
| (_| | | | (_| | | | (_| |
\__,_|_| \__,_|_| \__,_|
Processing 'test.tex' (size: 42 bytes, last modified: 11/12/2018
12:41:56), please wait.
[DR] (CleanX) Cleaning feature
-----------------------------------------------------------------
Author: Paulo Cereda
About to run: [ rm, -f, /home/paulo/foo.aux ]
[DR] (CleanX) Cleaning feature
-----------------------------------------------------------------
Author: Paulo Cereda
About to run: [ rm, -f, /home/paulo/bar.aux ]
Total: 0.19 seconds