jpikl / rew Goto Github PK
View Code? Open in Web Editor NEWA text processing CLI tool that rewrites FS paths according to a pattern.
Home Page: https://jpikl.github.io/rew/
License: MIT License
A text processing CLI tool that rewrites FS paths according to a pattern.
Home Page: https://jpikl.github.io/rew/
License: MIT License
For example awk '{print substr($0,2,3)}'
vs rew '{n2-4}'
Add conditionals evaluation with Regexp to filters similar to case statement in shell scripts.
Using @
as conditional symbol (for avoiding mismatch with regexp symbols):
# Example with Path filter:
{f@\d+:number@[a-z]+:lower@[A-Z]:upper:mixed}
# Example with Regexp filter:
{=\w+@\d+:number@[a-z]+:lower@[A-Z]:upper:mixed}
# Example with Path filter:
echo '123.txt' | rew '{f@\d+:number@[a-z]+:lower@[A-Z]:UPPER:mixed}' # Will print 'number.txt'
echo 'name.txt' | rew '{f@\d+:number@[a-z]+:lower@[A-Z]:UPPER:mixed}' # Will print 'lower.txt'
echo 'OUTPUT.txt' | rew '{f@\d+:number@[a-z]+:lower@[A-Z]:UPPER:mixed}' # Will print 'UPPER.txt'
echo 'file123.txt' | rew '{f@\d+:number@[a-z]+:lower@[A-Z]:UPPER:mixed}' # Will print 'mixed.png'
# Example with Regexp filter:
echo 'file123.txt' | rew '{=\w+@\d+:number@[a-z]+:lower@[A-Z]:UPPER:mixed}' # Will print 'file-number.txt'
echo 'file123.txt' | rew '{=\w+@\d+:number@[a-z]+:lower@[A-Z]:UPPER:mixed}' # Will print 'lower123.txt'
echo 'smallBIG.txt' | rew '{=\w+@\d+:number@[a-z]+:lower@[A-Z]:UPPER:mixed}' # Will print 'smallUPPER.LOG'
echo 'file123+456.png' | rew '{=\w+@\d+:number@[a-z]+:lower@[A-Z]:UPPER:mixed}' # Will print 'mixed+456.png'
Currently {n2-5}
means substring from 2nd to 5th character (inclusive).
The same could be written using an alternative syntax {n2+3}
... substring from 2nd character with length 3.
Use clap App#help_heading (currently not working when using derive macros).
Sections:
New filters
{oN:S}
- Split input value using separator S
, output N-th field.{oN}
- Split input value using default separator (tab), output N-th field.
o
= forward indexing / O
= backward indexing{qN:S}
- Like o
but separator is a regular expressionNew cli options
-f, --field-separator <string>
- Set default separator for $
flilterIntercept Clap initialization and use common::help::highlight_help
to add extra colors to app/args description.
pub trait Options: Clap {
fn parse_with_highlight() -> Self {
let mut app = <Self as IntoApp>::into_app();
// Modify app long_about
if let Some(value) = app.get_about() {
let mut buffer = Buffer::ansi();
highlight_help(&mut buffer, value).unwrap();
let result = std::str::from_utf8(buffer.as_slice()).unwrap();
app = app.long_about(result.to_string());
}
// Modify app.args. long_about...
<Self as FromArgMatches>::from_arg_matches(&app.get_matches())
}
}
Instead of a single executable rew
with all of the filtering functionality, let's split the project into more smaller cli tools, where every tool does one separate thing.
rew
subcommands. For example:
t
filter becomes rew trim [-s|--start] [-e|--end]
subcommand.r
filter becomes rew replace <what> [replacement]
subcommand.c
filter becomes rew seq
subcommand.C
filter becomes rew parent | rew count
where parent
subcommand prints parent directory and count
subcommand print number of occurrences of input lines.rew x
subcommand:
rew 'img_{C}.{e|l|r:e}'
rew 'img_{seq}.{ext | lower | replace e}'
rew
will run {a | b | ...c}
pipelines in separate threads-0, --null
flag to process NUL separated lines.REW_NULL
environment variable to enable -0, --null
behavior globally.split
and join
.mvb
/cpb
tools will be dropped in favor of generation of executable shell code.Generate using https://rust-cli.github.io/book/in-depth/docs.html
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.