Skip to content

Commit

Permalink
v0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
shenwei356 committed Nov 12, 2024
1 parent d7170d4 commit c7a3b3f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
- rush v0.6.0
- 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`.
- supports outputting "{}" with the replacement string "{{}}". `echo a/b | rush 'echo {{}}'` outputs `{}`.
- rush v0.5.7
- fix a bug for the input with "{}". [#61](https://github.com/shenwei356/rush/issues/61)
- rush v0.5.6
Expand Down
36 changes: 27 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Major:
- **Settable records sending to every command** (`-n`, default `1`). (`-n/--max-args` in GNU parallel)
- **Settable field delimiter** (`-d`, default `\s+`). (Same `-d/--delimiter` in GNU parallel)
- **Practical replacement strings** (like GNU parallel):
- `{{}}`, "{}" itself
- `{#}`, job ID. (Same in GNU parallel)
- `{}`, full data. (Same in GNU parallel)
- `{n}`, `n`th field in delimiter-delimited data. (Same in GNU parallel)
Expand Down Expand Up @@ -96,20 +97,20 @@ Note that speed is not the #.1 target, especially for processes that last long.

#### Method 1: Download binaries

[rush v0.5.7](https://github.com/shenwei356/rush/releases/tag/v0.5.7)
[![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)
[rush v0.6.0](https://github.com/shenwei356/rush/releases/tag/v0.6.0)
[![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)

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

OS |Arch |File, (中国镜像) |Download Count
:------|:---------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)


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

1. Input containing `{}` (since v0.6.0)

$ echo "a attr{href}"="h4 text{}" | rush -T b -k -D "=" 'echo "{}"'
a attr{href}
h4 text{}

$ echo -ne "a{},b{{}},c{d}" | rush -D , -k "echo {}"
a{}
b{{}}
c{d}

1. Output `{}` itself (since v0.6.0)

$ echo abc | rush 'echo "{} {{}}"'
abc {}

1. Dirname (`{/}`) and basename (`{%}`) and remove custom suffix (`{^suffix}`)

$ echo dir/file_1.txt.gz | rush 'echo {/} {%} {^_1.txt.gz}'
Expand Down
2 changes: 1 addition & 1 deletion helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
)

// VERSION of this package
const VERSION = "0.5.7"
const VERSION = "0.6.0"

func isStdin(file string) bool {
return file == "-"
Expand Down
3 changes: 2 additions & 1 deletion root.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@ Replacement strings in commands:
{#} job ID
{n} nth field in delimiter-delimited data
{/} dirname
{%%} basename
{%%} basename
{.} remove the last file extension
{:} remove all file extensions.
{^suffix} remove suffix
{@regexp} capture submatch using regular expression
{{}} "{}" itself
Combinations:
{%%.}, {%%:} basename without extension
Expand Down
25 changes: 19 additions & 6 deletions string_repl.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,20 @@ var rePlaceHolder = regexp.MustCompile(`\{([^\{\}}]*)\}`)
var reChars = regexp.MustCompile(`\d+|.`)
var reCharsCheck = regexp.MustCompile(`^(\d+)*.*$`)

var rePairedBrackets = regexp.MustCompile(`\{\}`)
var rePairedBrackets2 = regexp.MustCompile(`\{\{\}\}`)
var pairedBracketsReplace = "shenwei356_rush_magic"

func fillCommand(config Config, command string, chunk Chunk) (string, error) {
s, err := _fillCommand(config, rePairedBrackets2.ReplaceAllString(command, pairedBracketsReplace), chunk)
if err != nil {
return s, err
}
s = strings.ReplaceAll(s, pairedBracketsReplace, "{}")
return s, err
}

func _fillCommand(config Config, command string, chunk Chunk) (string, error) {
founds := rePlaceHolder.FindAllStringSubmatchIndex(command, -1)
if len(founds) == 0 {
return command, nil
Expand All @@ -59,6 +72,10 @@ func fillCommand(config Config, command string, chunk Chunk) (string, error) {
return "", nil
}

if rePairedBrackets.MatchString(fieldsStr) {
fieldsStr = rePairedBrackets.ReplaceAllString(fieldsStr, pairedBracketsReplace)
}

var fields []string

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

if chars == "" {
if config.GreedyCount == 0 {
target = "{}"
} else {
target = fieldsStr
}
target = fieldsStr
} else if chars == "#" {
target = fmt.Sprintf("%d", chunk.ID)
} else if !reCharsCheck.MatchString(chars) {
Expand Down Expand Up @@ -186,5 +199,5 @@ func fillCommand(config Config, command string, chunk Chunk) (string, error) {
return buf.String(), nil
}
config.GreedyCount--
return fillCommand(config, buf.String(), chunk)
return _fillCommand(config, buf.String(), chunk)
}

0 comments on commit c7a3b3f

Please sign in to comment.