From c7a3b3f5624453d82167bc090d3876dade48a51e Mon Sep 17 00:00:00 2001 From: Wei Shen Date: Tue, 12 Nov 2024 15:36:35 +0800 Subject: [PATCH] v0.6.0 --- CHANGELOG.md | 3 +++ README.md | 36 +++++++++++++++++++++++++++--------- helper.go | 2 +- root.go | 3 ++- string_repl.go | 25 +++++++++++++++++++------ 5 files changed, 52 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c41b769..c513c04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 8a2a48f..0223405 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 @@ -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 @@ -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}' diff --git a/helper.go b/helper.go index e479b2e..cd5add4 100644 --- a/helper.go +++ b/helper.go @@ -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 == "-" diff --git a/root.go b/root.go index 18c874f..58b9967 100644 --- a/root.go +++ b/root.go @@ -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 diff --git a/string_repl.go b/string_repl.go index 0a10690..daeee45 100644 --- a/string_repl.go +++ b/string_repl.go @@ -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 @@ -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 @@ -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) { @@ -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) }