Code Monkey home page Code Monkey logo

rew's People

Contributors

jpikl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

0xack13

rew's Issues

Add conditionals to regexp filters

Add conditionals Regexp to filters

Add conditionals evaluation with Regexp to filters similar to case statement in shell scripts.

Syntax Example

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}

Syntax Example

# 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'

Allow start+length syntax for substring range

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.

Field selector filter

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 expression

New cli options

  • -f, --field-separator <string> - Set default separator for $ flilter

Extra colors in help

Intercept 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())
    }
}

New architecture

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.

  • Previous filters will be implemented as separate 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.
  • Pipeline composition will be done using rew x subcommand:
    • Former usage: rew 'img_{C}.{e|l|r:e}'
    • New usage: rew 'img_{seq}.{ext | lower | replace e}'
  • rew will run {a | b | ...c} pipelines in separate threads
  • Every pipeline will consume/produce lines.
  • Every subcommand will support -0, --null flag to process NUL separated lines.
  • There will be REW_NULL environment variable to enable -0, --null behavior globally.
  • Former cli options for custom input/output line separator will be implemented as a separate subcommands split and join.
  • Alternative output modes (diff/json lines) will not be supported anymore.
  • Auxiliary mvb/cpb tools will be dropped in favor of generation of executable shell code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.