diff --git a/README.md b/README.md index 2de8b4d..ed19007 100644 --- a/README.md +++ b/README.md @@ -46,11 +46,28 @@ Use the `{}` syntax to use a specific capturing group. - `{2}` matches the second capturing group - and so on +#### Coloring + +Coloring a reference to a capturing group can be done via `{1:}`. + +`` can be one of the following values: + +- `black` +- `red` +- `green` +- `yellow` +- `blue` +- `magenta` +- `cyan` +- `white` + +Leaving the color argument empty results into the default color. + #### Formatting -When referencing capturing groups, you can add a specific format for some data types as well using a simplified printf syntax. +When referencing capturing groups, you can add a specific format for some data types using a simplified printf syntax. -You can use them using this syntax: `{1:%d}`. It will parse the first capturing group into an integer to get rid of leading zeros. Additionally, you can provide a given amount of leading zeros via: `{1:%03d}` for a total length of 3 digits. +You can use them using this syntax: `{1::%d}`. It will parse the first capturing group into an integer to get rid of leading zeros. Additionally, you can provide a given amount of leading zeros via: `{1::%03d}` for a total length of 3 digits. The same method can also be applied to `%f` to further format floating point values. See a full list of formatting options at [Go's fmt spec](https://pkg.go.dev/fmt). @@ -61,7 +78,7 @@ Currently only `%s`, `%d`, `%f` and `%g` are supported though. Mutators are a simple way of manipulating number values like integers and floats using a simple math-like expression -You can provide a mutator using the syntax: `{1:%d:+1}`. It will parse the first capturing group into an integer, adds 1 and then formats the result using the printf format `%d`. +You can provide a mutator using the syntax: `{1::%d:+1}`. It will parse the first capturing group into an integer, adds 1 and then formats the result using the printf format `%d`. A mutator always consists of an operator and a value. In the example above `+` is the operator and `1` is the value. @@ -71,11 +88,11 @@ The following operators are supported for `%d`, `%f` and `%g` formats: - `*` - `/` -It is possible to add multiple mutators by just concatenating them: `{1:%d:*2+1}`. +It is possible to add multiple mutators by just concatenating them: `{1::%d:*2+1}`. **Multiple mutators will not follow any order of operations. They are simply applied from left to right!** -Furthermore you can reference caputring groups which will be parsed as the same type to apply its value. This is done via the following syntax: `{1:%d:+(2)}`. It will parse the first and second capturing group into integers and adds them. +Furthermore you can reference caputring groups which will be parsed as the same type to apply its value. This is done via the following syntax: `{1::%d:+(2)}`. It will parse the first and second capturing group into integers and adds them. ### Handling unmatched lines @@ -153,7 +170,7 @@ Input: Command: ```sh -format -i '\d+' -o '{0:%d}' +format -i '\d+' -o '{0::%d}' ``` Output: @@ -175,7 +192,7 @@ Input: Command: ```sh -format -i '(\d{4})-(\d{2})-(\d{2})' -o 'day: {3:%d} | month: {2:%d} | year: {1}' +format -i '(\d{4})-(\d{2})-(\d{2})' -o 'day: {3::%d} | month: {2::%d} | year: {1}' ``` Output: @@ -198,8 +215,8 @@ Input: Command: ```sh -format -i '(\d{4})-(\d{2})-(\d{2})' -o 'day: {3:%d} | month: {2:%d} | year: {1}' -k | -format -i '(\d{2})\.(\d{2})\.(\d{4})' -o 'day: {1:%d} | month: {2:%d} | year: {3}' -k +format -i '(\d{4})-(\d{2})-(\d{2})' -o 'day: {3::%d} | month: {2::%d} | year: {1}' -k | +format -i '(\d{2})\.(\d{2})\.(\d{4})' -o 'day: {1::%d} | month: {2::%d} | year: {3}' -k ``` Output: @@ -231,7 +248,7 @@ day: 02 Command: ```sh -format -n 3 -i '^year: (\d{4})\nmonth: (\d{2})\nday: (\d{2})$' -o 'day: {3:%d} | month: {2:%d} | year: {1}' +format -n 3 -i '^year: (\d{4})\nmonth: (\d{2})\nday: (\d{2})$' -o 'day: {3::%d} | month: {2::%d} | year: {1}' ``` Output: @@ -255,7 +272,7 @@ Input: Command: ```sh -format -i '(-?\d+) (-?\d+(?:.\d+)?)' -o '{1} + {2} = {1:%g:+(2)}' +format -i '(-?\d+) (-?\d+(?:.\d+)?)' -o '{1} + {2} = {1::%g:+(2)}' ``` Output: @@ -279,7 +296,7 @@ Output of `ls`: Command: ```sh -ls | format -i '(\d+)\.jpg' -o 'mv "{0}" "{1:%d:+1}.jpg"' | xargs -0 sh -c +ls | format -i '(\d+)\.jpg' -o 'mv "{0}" "{1::%d:+1}.jpg"' | xargs -0 sh -c ``` Output of `ls` afterwards: @@ -320,7 +337,7 @@ Output of `ls`: Command: ```sh -bulkrename '(\d+)\.jpg' '{1:%d:+1}.jpg' +bulkrename '(\d+)\.jpg' '{1::%d:+1}.jpg' ``` Output: @@ -329,12 +346,12 @@ mv "000.jpg" "1.jpg" mv "001.jpg" "2.jpg" mv "002.jpg" "3.jpg" -execute commands with 'bulkrename (\d+)\.jpg {1:%d:+1}.jpg exec' +execute commands with 'bulkrename (\d+)\.jpg {1::%d:+1}.jpg exec' ``` Command: ```sh -bulkrename '(\d+)\.jpg' '{1:%d:+1}.jpg' exec +bulkrename '(\d+)\.jpg' '{1::%d:+1}.jpg' exec ``` Output of `ls` afterwards: