Skip to content

Commit

Permalink
v2.9.0: new flag --list-sep
Browse files Browse the repository at this point in the history
  • Loading branch information
shenwei356 committed Aug 6, 2019
1 parent 71e1d68 commit 68485d2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
- v2.9.0
- add flag `--list-sep` to set separater for list of found paths.
- v2.8.1
- matching directories when using flag `--only-dir` or `-D/--including-dir`.
- v2.8.0
Expand Down
31 changes: 13 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@

#### Method 1: Download binaries

[brename v2.8.1](https://github.com/shenwei356/brename/releases/tag/v2.8.1)
[![Github Releases (by Release)](https://img.shields.io/github/downloads/shenwei356/brename/v2.8.1/total.svg)](https://github.com/shenwei356/brename/releases/tag/v2.8.1)
[brename v2.9.0](https://github.com/shenwei356/brename/releases/tag/v2.9.0)
[![Github Releases (by Release)](https://img.shields.io/github/downloads/shenwei356/brename/v2.9.0/total.svg)](https://github.com/shenwei356/brename/releases/tag/v2.9.0)

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

OS |Arch |File, 中国镜像 |Download Count
:------|:---------|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Linux |32-bit |[brename_linux_386.tar.gz](https://github.com/shenwei356/brename/releases/download/v2.8.1/brename_linux_386.tar.gz),<br/> [中国镜像](http://app.shenwei.me/data/brename/brename_linux_386.tar.gz) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/brename/latest/brename_linux_386.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/brename/releases/download/v2.8.1/brename_linux_386.tar.gz)
Linux |**64-bit**|[**brename_linux_amd64.tar.gz**](https://github.com/shenwei356/brename/releases/download/v2.8.1/brename_linux_amd64.tar.gz),<br/> [中国镜像](http://app.shenwei.me/data/brename/brename_linux_amd64.tar.gz) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/brename/latest/brename_linux_amd64.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/brename/releases/download/v2.8.1/brename_linux_amd64.tar.gz)
OS X |32-bit |[brename_darwin_386.tar.gz](https://github.com/shenwei356/brename/releases/download/v2.8.1/brename_darwin_386.tar.gz),<br/> [中国镜像](http://app.shenwei.me/data/brename/brename_darwin_386.tar.gz) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/brename/latest/brename_darwin_386.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/brename/releases/download/v2.8.1/brename_darwin_386.tar.gz)
OS X |**64-bit**|[**brename_darwin_amd64.tar.gz**](https://github.com/shenwei356/brename/releases/download/v2.8.1/brename_darwin_amd64.tar.gz),<br/> [中国镜像](http://app.shenwei.me/data/brename/brename_darwin_amd64.tar.gz) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/brename/latest/brename_darwin_amd64.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/brename/releases/download/v2.8.1/brename_darwin_amd64.tar.gz)
Windows|32-bit |[brename_windows_386.exe.tar.gz](https://github.com/shenwei356/brename/releases/download/v2.8.1/brename_windows_386.exe.tar.gz),<br/> [中国镜像](http://app.shenwei.me/data/brename/brename_windows_386.exe.tar.gz) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/brename/latest/brename_windows_386.exe.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/brename/releases/download/v2.8.1/brename_windows_386.exe.tar.gz)
Windows|**64-bit**|[**brename_windows_amd64.exe.tar.gz**](https://github.com/shenwei356/brename/releases/download/v2.8.1/brename_windows_amd64.exe.tar.gz),<br/> [中国镜像](http://app.shenwei.me/data/brename/brename_windows_amd64.exe.tar.gz)|[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/brename/latest/brename_windows_amd64.exe.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/brename/releases/download/v2.8.1/brename_windows_amd64.exe.tar.gz)
Linux |32-bit |[brename_linux_386.tar.gz](https://github.com/shenwei356/brename/releases/download/v2.9.0/brename_linux_386.tar.gz),<br/> [中国镜像](http://app.shenwei.me/data/brename/brename_linux_386.tar.gz) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/brename/latest/brename_linux_386.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/brename/releases/download/v2.9.0/brename_linux_386.tar.gz)
Linux |**64-bit**|[**brename_linux_amd64.tar.gz**](https://github.com/shenwei356/brename/releases/download/v2.9.0/brename_linux_amd64.tar.gz),<br/> [中国镜像](http://app.shenwei.me/data/brename/brename_linux_amd64.tar.gz) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/brename/latest/brename_linux_amd64.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/brename/releases/download/v2.9.0/brename_linux_amd64.tar.gz)
OS X |32-bit |[brename_darwin_386.tar.gz](https://github.com/shenwei356/brename/releases/download/v2.9.0/brename_darwin_386.tar.gz),<br/> [中国镜像](http://app.shenwei.me/data/brename/brename_darwin_386.tar.gz) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/brename/latest/brename_darwin_386.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/brename/releases/download/v2.9.0/brename_darwin_386.tar.gz)
OS X |**64-bit**|[**brename_darwin_amd64.tar.gz**](https://github.com/shenwei356/brename/releases/download/v2.9.0/brename_darwin_amd64.tar.gz),<br/> [中国镜像](http://app.shenwei.me/data/brename/brename_darwin_amd64.tar.gz) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/brename/latest/brename_darwin_amd64.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/brename/releases/download/v2.9.0/brename_darwin_amd64.tar.gz)
Windows|32-bit |[brename_windows_386.exe.tar.gz](https://github.com/shenwei356/brename/releases/download/v2.9.0/brename_windows_386.exe.tar.gz),<br/> [中国镜像](http://app.shenwei.me/data/brename/brename_windows_386.exe.tar.gz) |[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/brename/latest/brename_windows_386.exe.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/brename/releases/download/v2.9.0/brename_windows_386.exe.tar.gz)
Windows|**64-bit**|[**brename_windows_amd64.exe.tar.gz**](https://github.com/shenwei356/brename/releases/download/v2.9.0/brename_windows_amd64.exe.tar.gz),<br/> [中国镜像](http://app.shenwei.me/data/brename/brename_windows_amd64.exe.tar.gz)|[![Github Releases (by Asset)](https://img.shields.io/github/downloads/shenwei356/brename/latest/brename_windows_amd64.exe.tar.gz.svg?maxAge=3600)](https://github.com/shenwei356/brename/releases/download/v2.9.0/brename_windows_amd64.exe.tar.gz)


Just [download](https://github.com/shenwei356/brename/releases) compressed
Expand All @@ -75,12 +75,9 @@ And then:

sudo cp brename /usr/local/bin/

1. Or add the current directory of the executable file to environment variable
`PATH`:

echo export PATH=\$PATH:\"$(pwd)\" >> ~/.bashrc
source ~/.bashrc
1. Or copy to anywhere in the environment variable `PATH`:

mkdir -p $HOME/bin/; cp brename $HOME/bin/

1. **For windows**, just copy `brename.exe` to `C:\WINDOWS\system32`.

Expand All @@ -98,7 +95,7 @@ And then:
brename -- a practical cross-platform command-line tool for safely batch renaming files/directories via regular expression
Version: 2.8.1
Version: 2.9.0
Author: Wei Shen <[email protected]>
Expand Down Expand Up @@ -159,6 +156,7 @@ Flags:
-k, --kv-file string tab-delimited key-value file for replacing key with value when using "{kv}" in -r (--replacement)
-l, --list only list paths that match pattern
-a, --list-abs list absolute path, using along with -l/--list
-s, --list-sep string separater for list of found paths (default "\n")
--max-depth int maximum depth for recursive search (0 for no limit)
--nr-width int minimum width for {nr} in flag -r/--replacement. e.g., formating "1" to "001" by --nr-width 3 (default 1)
--only-dir only rename directories
Expand All @@ -170,6 +168,7 @@ Flags:
-u, --undo undo the LAST successful operation
-v, --verbose int verbose level (0 for all, 1 for warning and error, 2 for only error) (default 0)
-V, --version print version information and check for update
```


Expand Down Expand Up @@ -266,7 +265,6 @@ Take a directory for example:
├── b.html
└── b.jpg


1. Renaming directory too (`-D/--including-dir`)

$ brename -p "a" -r "A" -R -D
Expand Down Expand Up @@ -330,7 +328,6 @@ Take a directory for example:
[INFO] checking: [ ok ] 'b.jpeg' -> 'pic-002.jpeg'
[INFO] 2 path(s) to be renamed


1. Replace submatch with corresponding value via key-value file (`-k/--kv-file`)

$ more kv.tsv
Expand Down Expand Up @@ -437,8 +434,6 @@ Take a directory for example:

# if you make more changes after renaming, you can
brename -U



## Real-world examples

Expand Down
16 changes: 14 additions & 2 deletions brename.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import (

var log *logging.Logger

var version = "2.8.1"
var version = "2.9.0"
var app = "brename"

// for detecting one case where two or more files are renamed to same new path
Expand Down Expand Up @@ -70,6 +70,7 @@ type Options struct {
ExcludeFilterRes []*regexp.Regexp

ListPath bool
ListPathSep string
ListAbsPath bool

ReplaceWithNR bool
Expand Down Expand Up @@ -236,6 +237,7 @@ func getOptions(cmd *cobra.Command) *Options {
ExcludeFilterRes: exfilterRes,

ListPath: getFlagBool(cmd, "list"),
ListPathSep: getFlagString(cmd, "list-sep"),
ListAbsPath: getFlagBool(cmd, "list-abs"),

ReplaceWithNR: replaceWithNR,
Expand Down Expand Up @@ -284,6 +286,7 @@ func init() {
RootCmd.Flags().StringSliceP("exclude-filters", "F", []string{}, `exclude file filter(s) (regular expression, case ignored). multiple values supported, e.g., -F ".html" -F ".htm", but ATTENTION: comma in filter is treated as separater of multiple filters`)

RootCmd.Flags().BoolP("list", "l", false, `only list paths that match pattern`)
RootCmd.Flags().StringP("list-sep", "s", "\n", `separater for list of found paths`)
RootCmd.Flags().BoolP("list-abs", "a", false, `list absolute path, using along with -l/--list`)

RootCmd.Flags().StringP("kv-file", "k", "",
Expand Down Expand Up @@ -548,6 +551,7 @@ Special replacement symbols:
var err error

go func() {
first := true
for op := range opCH {
if opt.ListPath {
if opt.ListAbsPath {
Expand All @@ -556,7 +560,12 @@ Special replacement symbols:
} else {
outPath = op.source
}
fmt.Println(outPath)
if first {
fmt.Print(outPath)
first = false
} else {
fmt.Print(opt.ListPathSep + outPath)
}
continue
}
if int(op.code) >= opt.Verbose {
Expand Down Expand Up @@ -602,6 +611,9 @@ Special replacement symbols:
continue
}
}
if opt.ListPath {
fmt.Println()
}
done <- 1
}()

Expand Down

0 comments on commit 68485d2

Please sign in to comment.