Skip to content

Commit c7a3b3f

Browse files
committed
v0.6.0
1 parent d7170d4 commit c7a3b3f

File tree

5 files changed

+52
-17
lines changed

5 files changed

+52
-17
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
- rush v0.6.0
2+
- fix variables containing "{}", the bug was introduced in v0.5.7, e.g., `rush -v 'p={}/{%}' 'echo {p}_1.fq'` outputs `a/b/b_1.fq`.
3+
- supports outputting "{}" with the replacement string "{{}}". `echo a/b | rush 'echo {{}}'` outputs `{}`.
14
- rush v0.5.7
25
- fix a bug for the input with "{}". [#61](https://github.com/shenwei356/rush/issues/61)
36
- rush v0.5.6

README.md

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Major:
5757
- **Settable records sending to every command** (`-n`, default `1`). (`-n/--max-args` in GNU parallel)
5858
- **Settable field delimiter** (`-d`, default `\s+`). (Same `-d/--delimiter` in GNU parallel)
5959
- **Practical replacement strings** (like GNU parallel):
60+
- `{{}}`, "{}" itself
6061
- `{#}`, job ID. (Same in GNU parallel)
6162
- `{}`, full data. (Same in GNU parallel)
6263
- `{n}`, `n`th field in delimiter-delimited data. (Same in GNU parallel)
@@ -96,20 +97,20 @@ Note that speed is not the #.1 target, especially for processes that last long.
9697

9798
#### Method 1: Download binaries
9899

99-
[rush v0.5.7](https://github.com/shenwei356/rush/releases/tag/v0.5.7)
100-
[![Github Releases (by Release)](https://img.shields.io/github/downloads/shenwei356/rush/v0.5.7/total.svg)](https://github.com/shenwei356/rush/releases/tag/v0.5.7)
100+
[rush v0.6.0](https://github.com/shenwei356/rush/releases/tag/v0.6.0)
101+
[![Github Releases (by Release)](https://img.shields.io/github/downloads/shenwei356/rush/v0.6.0/total.svg)](https://github.com/shenwei356/rush/releases/tag/v0.6.0)
101102

102103
***Tip: run `rush -V` to check update !!!***
103104

104105
OS |Arch |File, (中国镜像) |Download Count
105106
:------|:---------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
106-
Linux |32-bit |[rush_linux_386.tar.gz](https://github.com/shenwei356/rush/releases/download/v0.5.7/rush_linux_386.tar.gz), ([mirror](http://app.shenwei.me/data/rush/rush_linux_386.tar.gz)) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/rush/latest/rush_linux_386.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/rush/releases/download/v0.5.7/rush_linux_386.tar.gz)
107-
Linux |**64-bit**|[**rush_linux_amd64.tar.gz**](https://github.com/shenwei356/rush/releases/download/v0.5.7/rush_linux_amd64.tar.gz), ([mirror](http://app.shenwei.me/data/rush/rush_linux_amd64.tar.gz)) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/rush/latest/rush_linux_amd64.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/rush/releases/download/v0.5.7/rush_linux_amd64.tar.gz)
108-
Linux |**arm64** |[**rush_linux_arm64.tar.gz**](https://github.com/shenwei356/rush/releases/download/v0.5.7/rush_linux_arm64.tar.gz), ([mirror](http://app.shenwei.me/data/rush/rush_linux_arm64.tar.gz)) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/rush/latest/rush_linux_arm64.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/rush/releases/download/v0.5.7/rush_linux_arm64.tar.gz)
109-
OS X |**64-bit**|[**rush_darwin_amd64.tar.gz**](https://github.com/shenwei356/rush/releases/download/v0.5.7/rush_darwin_amd64.tar.gz), ([mirror](http://app.shenwei.me/data/rush/rush_darwin_amd64.tar.gz)) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/rush/latest/rush_darwin_amd64.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/rush/releases/download/v0.5.7/rush_darwin_amd64.tar.gz)
110-
OS X |**arm64** |[**rush_darwin_arm64.tar.gz**](https://github.com/shenwei356/rush/releases/download/v0.5.7/rush_darwin_arm64.tar.gz), ([mirror](http://app.shenwei.me/data/rush/rush_darwin_arm64.tar.gz)) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/rush/latest/rush_darwin_arm64.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/rush/releases/download/v0.5.7/rush_darwin_arm64.tar.gz)
111-
Windows|32-bit |[rush_windows_386.exe.tar.gz](https://github.com/shenwei356/rush/releases/download/v0.5.7/rush_windows_386.exe.tar.gz), ([mirror](http://app.shenwei.me/data/rush/rush_windows_386.exe.tar.gz)) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/rush/latest/rush_windows_386.exe.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/rush/releases/download/v0.5.7/rush_windows_386.exe.tar.gz)
112-
Windows|**64-bit**|[**rush_windows_amd64.exe.tar.gz**](https://github.com/shenwei356/rush/releases/download/v0.5.7/rush_windows_amd64.exe.tar.gz), ([mirror](http://app.shenwei.me/data/rush/rush_windows_amd64.exe.tar.gz))|[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/rush/latest/rush_windows_amd64.exe.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/rush/releases/download/v0.5.7/rush_windows_amd64.exe.tar.gz)
107+
Linux |32-bit |[rush_linux_386.tar.gz](https://github.com/shenwei356/rush/releases/download/v0.6.0/rush_linux_386.tar.gz), ([mirror](http://app.shenwei.me/data/rush/rush_linux_386.tar.gz)) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/rush/latest/rush_linux_386.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/rush/releases/download/v0.6.0/rush_linux_386.tar.gz)
108+
Linux |**64-bit**|[**rush_linux_amd64.tar.gz**](https://github.com/shenwei356/rush/releases/download/v0.6.0/rush_linux_amd64.tar.gz), ([mirror](http://app.shenwei.me/data/rush/rush_linux_amd64.tar.gz)) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/rush/latest/rush_linux_amd64.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/rush/releases/download/v0.6.0/rush_linux_amd64.tar.gz)
109+
Linux |**arm64** |[**rush_linux_arm64.tar.gz**](https://github.com/shenwei356/rush/releases/download/v0.6.0/rush_linux_arm64.tar.gz), ([mirror](http://app.shenwei.me/data/rush/rush_linux_arm64.tar.gz)) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/rush/latest/rush_linux_arm64.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/rush/releases/download/v0.6.0/rush_linux_arm64.tar.gz)
110+
OS X |**64-bit**|[**rush_darwin_amd64.tar.gz**](https://github.com/shenwei356/rush/releases/download/v0.6.0/rush_darwin_amd64.tar.gz), ([mirror](http://app.shenwei.me/data/rush/rush_darwin_amd64.tar.gz)) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/rush/latest/rush_darwin_amd64.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/rush/releases/download/v0.6.0/rush_darwin_amd64.tar.gz)
111+
OS X |**arm64** |[**rush_darwin_arm64.tar.gz**](https://github.com/shenwei356/rush/releases/download/v0.6.0/rush_darwin_arm64.tar.gz), ([mirror](http://app.shenwei.me/data/rush/rush_darwin_arm64.tar.gz)) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/rush/latest/rush_darwin_arm64.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/rush/releases/download/v0.6.0/rush_darwin_arm64.tar.gz)
112+
Windows|32-bit |[rush_windows_386.exe.tar.gz](https://github.com/shenwei356/rush/releases/download/v0.6.0/rush_windows_386.exe.tar.gz), ([mirror](http://app.shenwei.me/data/rush/rush_windows_386.exe.tar.gz)) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/rush/latest/rush_windows_386.exe.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/rush/releases/download/v0.6.0/rush_windows_386.exe.tar.gz)
113+
Windows|**64-bit**|[**rush_windows_amd64.exe.tar.gz**](https://github.com/shenwei356/rush/releases/download/v0.6.0/rush_windows_amd64.exe.tar.gz), ([mirror](http://app.shenwei.me/data/rush/rush_windows_amd64.exe.tar.gz))|[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/rush/latest/rush_windows_amd64.exe.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/rush/releases/download/v0.6.0/rush_windows_amd64.exe.tar.gz)
113114

114115

115116
Just [download](https://github.com/shenwei356/rush/releases) compressed
@@ -195,6 +196,7 @@ Replacement strings in commands:
195196
{:} remove all file extensions.
196197
{^suffix} remove suffix
197198
{@regexp} capture submatch using regular expression
199+
{{}} "{}" itself
198200
199201
Combinations:
200202
{%.}, {%:} basename without extension
@@ -351,6 +353,22 @@ Flags:
351353
python: can't open file 'unexisted_script.py': [Errno 2] No such file or directory
352354
[ERRO] wait command: python unexisted_script.py: exit status 2
353355

356+
1. Input containing `{}` (since v0.6.0)
357+
358+
$ echo "a attr{href}"="h4 text{}" | rush -T b -k -D "=" 'echo "{}"'
359+
a attr{href}
360+
h4 text{}
361+
362+
$ echo -ne "a{},b{{}},c{d}" | rush -D , -k "echo {}"
363+
a{}
364+
b{{}}
365+
c{d}
366+
367+
1. Output `{}` itself (since v0.6.0)
368+
369+
$ echo abc | rush 'echo "{} {{}}"'
370+
abc {}
371+
354372
1. Dirname (`{/}`) and basename (`{%}`) and remove custom suffix (`{^suffix}`)
355373

356374
$ echo dir/file_1.txt.gz | rush 'echo {/} {%} {^_1.txt.gz}'

helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
)
3131

3232
// VERSION of this package
33-
const VERSION = "0.5.7"
33+
const VERSION = "0.6.0"
3434

3535
func isStdin(file string) bool {
3636
return file == "-"

root.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,12 @@ Replacement strings in commands:
7474
{#} job ID
7575
{n} nth field in delimiter-delimited data
7676
{/} dirname
77-
{%%} basename
77+
{%%} basename
7878
{.} remove the last file extension
7979
{:} remove all file extensions.
8080
{^suffix} remove suffix
8181
{@regexp} capture submatch using regular expression
82+
{{}} "{}" itself
8283
8384
Combinations:
8485
{%%.}, {%%:} basename without extension

string_repl.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,20 @@ var rePlaceHolder = regexp.MustCompile(`\{([^\{\}}]*)\}`)
3333
var reChars = regexp.MustCompile(`\d+|.`)
3434
var reCharsCheck = regexp.MustCompile(`^(\d+)*.*$`)
3535

36+
var rePairedBrackets = regexp.MustCompile(`\{\}`)
37+
var rePairedBrackets2 = regexp.MustCompile(`\{\{\}\}`)
38+
var pairedBracketsReplace = "shenwei356_rush_magic"
39+
3640
func fillCommand(config Config, command string, chunk Chunk) (string, error) {
41+
s, err := _fillCommand(config, rePairedBrackets2.ReplaceAllString(command, pairedBracketsReplace), chunk)
42+
if err != nil {
43+
return s, err
44+
}
45+
s = strings.ReplaceAll(s, pairedBracketsReplace, "{}")
46+
return s, err
47+
}
48+
49+
func _fillCommand(config Config, command string, chunk Chunk) (string, error) {
3750
founds := rePlaceHolder.FindAllStringSubmatchIndex(command, -1)
3851
if len(founds) == 0 {
3952
return command, nil
@@ -59,6 +72,10 @@ func fillCommand(config Config, command string, chunk Chunk) (string, error) {
5972
return "", nil
6073
}
6174

75+
if rePairedBrackets.MatchString(fieldsStr) {
76+
fieldsStr = rePairedBrackets.ReplaceAllString(fieldsStr, pairedBracketsReplace)
77+
}
78+
6279
var fields []string
6380

6481
var chars, char, target string
@@ -70,11 +87,7 @@ func fillCommand(config Config, command string, chunk Chunk) (string, error) {
7087
target = fieldsStr
7188

7289
if chars == "" {
73-
if config.GreedyCount == 0 {
74-
target = "{}"
75-
} else {
76-
target = fieldsStr
77-
}
90+
target = fieldsStr
7891
} else if chars == "#" {
7992
target = fmt.Sprintf("%d", chunk.ID)
8093
} else if !reCharsCheck.MatchString(chars) {
@@ -186,5 +199,5 @@ func fillCommand(config Config, command string, chunk Chunk) (string, error) {
186199
return buf.String(), nil
187200
}
188201
config.GreedyCount--
189-
return fillCommand(config, buf.String(), chunk)
202+
return _fillCommand(config, buf.String(), chunk)
190203
}

0 commit comments

Comments
 (0)