Skip to content

Commit

Permalink
v2.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
shenwei356 committed Mar 21, 2019
1 parent 6cc7f90 commit e4253ed
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ brename
t.*
binaries
brename_*
*.brename_detail.txt
36 changes: 36 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
- v2.8.0
- handle files and then dirs in a directory.
- ignore files matched with pattern but not found in kv files when using {kv}.
- add flag `--max-depth` to limit search depth.
- add falg `--only-dir` to only handle directories.
- v2.7.0
- add flag `-u/--undo` and `-U/--force-undo` to undo the LAST successful operation.
- v2.6.0
- better conflict detection.
- add flag `-o/--overwrite-mode` to choose 0) reporting error, 1) overwriting existed files or 2) skipping renaming.
- v2.5.2
- add flag `--nr-width` to fill leading `0`s for `{nr}`.
- v2.5.0
- skipping directories without read permission.
- add flag `-l/--list` for only listing paths that match pattern.
- v2.4.0
- supporting automatically mkdir. [#5](https://github.com/shenwei356/brename/issues/5)
- v2.3.0
- add option -e/--ignore-ext for ignore file extension. [#4](https://github.com/shenwei356/brename/issues/4)
- build static binaries.
- v2.2.0
- Add supporting replace with ascending integer (`{nr}` in value of flag `-r/--replacement`).
- Add supporting renaming submatch with corresponding value via key-value file (`-k/--kv-file`) (`{kv}` in value of flag `-r/--replacement`).
- v2.1.3
- fix log error, and bug of wrongly including dir.
- v2.1.2
- fix windows color via https://github.com/mattn/go-colorable. [#1](https://github.com/shenwei356/brename/pull/1)
- v2.1.1
- changing output format.
- v2.1
- add include and exclude file filters.
- v2.0
- A safer rewritten version.
- v1.0
- v1.0

Empty file modified LICENSE
100755 → 100644
Empty file.
21 changes: 12 additions & 9 deletions README.md
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@

#### Method 1: Download binaries

[brename v2.7.0](https://github.com/shenwei356/brename/releases/tag/v2.7.0)
[![Github Releases (by Release)](https://img.shields.io/github/downloads/shenwei356/brename/v2.7.0/total.svg)](https://github.com/shenwei356/brename/releases/tag/v2.7.0)
[brename v2.8.0](https://github.com/shenwei356/brename/releases/tag/v2.8.0)
[![Github Releases (by Release)](https://img.shields.io/github/downloads/shenwei356/brename/v2.8.0/total.svg)](https://github.com/shenwei356/brename/releases/tag/v2.8.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.7.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.7.0/brename_linux_386.tar.gz)
Linux |**64-bit**|[**brename_linux_amd64.tar.gz**](https://github.com/shenwei356/brename/releases/download/v2.7.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.7.0/brename_linux_amd64.tar.gz)
OS X |32-bit |[brename_darwin_386.tar.gz](https://github.com/shenwei356/brename/releases/download/v2.7.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.7.0/brename_darwin_386.tar.gz)
OS X |**64-bit**|[**brename_darwin_amd64.tar.gz**](https://github.com/shenwei356/brename/releases/download/v2.7.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.7.0/brename_darwin_amd64.tar.gz)
Windows|32-bit |[brename_windows_386.exe.tar.gz](https://github.com/shenwei356/brename/releases/download/v2.7.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.7.0/brename_windows_386.exe.tar.gz)
Windows|**64-bit**|[**brename_windows_amd64.exe.tar.gz**](https://github.com/shenwei356/brename/releases/download/v2.7.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.7.0/brename_windows_amd64.exe.tar.gz)
Linux |32-bit |[brename_linux_386.tar.gz](https://github.com/shenwei356/brename/releases/download/v2.8.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.8.0/brename_linux_386.tar.gz)
Linux |**64-bit**|[**brename_linux_amd64.tar.gz**](https://github.com/shenwei356/brename/releases/download/v2.8.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.8.0/brename_linux_amd64.tar.gz)
OS X |32-bit |[brename_darwin_386.tar.gz](https://github.com/shenwei356/brename/releases/download/v2.8.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.8.0/brename_darwin_386.tar.gz)
OS X |**64-bit**|[**brename_darwin_amd64.tar.gz**](https://github.com/shenwei356/brename/releases/download/v2.8.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.8.0/brename_darwin_amd64.tar.gz)
Windows|32-bit |[brename_windows_386.exe.tar.gz](https://github.com/shenwei356/brename/releases/download/v2.8.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.8.0/brename_windows_386.exe.tar.gz)
Windows|**64-bit**|[**brename_windows_amd64.exe.tar.gz**](https://github.com/shenwei356/brename/releases/download/v2.8.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.8.0/brename_windows_amd64.exe.tar.gz)


Just [download](https://github.com/shenwei356/brename/releases) compressed
Expand Down Expand Up @@ -95,9 +95,10 @@ And then:
## Usage

```
brename -- a practical cross-platform command-line tool for safely batch renaming files/directories via regular expression
Version: 2.7.0
Version: 2.8.0
Author: Wei Shen <[email protected]>
Expand Down Expand Up @@ -158,7 +159,9 @@ 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
--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
-o, --overwrite-mode int overwrite mode (0 for reporting error, 1 for overwrite, 2 for not renaming) (default 0)
-p, --pattern string search pattern (regular expression)
-R, --recursive rename recursively
Expand Down
35 changes: 23 additions & 12 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.7.2"
var version = "2.8.0"
var app = "brename"

// for detecting one case where two or more files are renamed to same new path
Expand All @@ -59,6 +59,8 @@ type Options struct {
Replacement string
Recursive bool
IncludingDir bool
OnlyDir bool
MaxDepth int
IgnoreCase bool
IgnoreExt bool

Expand Down Expand Up @@ -223,6 +225,8 @@ func getOptions(cmd *cobra.Command) *Options {
Replacement: replacement,
Recursive: getFlagBool(cmd, "recursive"),
IncludingDir: getFlagBool(cmd, "including-dir"),
OnlyDir: getFlagBool(cmd, "only-dir"),
MaxDepth: getFlagNonNegativeInt(cmd, "max-depth"),
IgnoreCase: ignoreCase,
IgnoreExt: getFlagBool(cmd, "ignore-ext"),

Expand Down Expand Up @@ -271,6 +275,8 @@ func init() {
RootCmd.Flags().StringP("replacement", "r", "", `replacement. capture variables supported. e.g. $1 represents the first submatch. ATTENTION: for *nix OS, use SINGLE quote NOT double quotes or use the \ escape character. Ascending integer is also supported by "{nr}"`)
RootCmd.Flags().BoolP("recursive", "R", false, "rename recursively")
RootCmd.Flags().BoolP("including-dir", "D", false, "rename directories")
RootCmd.Flags().BoolP("only-dir", "", false, "only rename directories")
RootCmd.Flags().IntP("max-depth", "", 0, "maximum depth for recursive search (0 for no limit)")
RootCmd.Flags().BoolP("ignore-case", "i", false, "ignore case")
RootCmd.Flags().BoolP("ignore-ext", "e", false, "ignore file extension. i.e., replacement does not change file extension")

Expand Down Expand Up @@ -600,7 +606,7 @@ Special replacement symbols:
}()

for _, path := range getFileList(args) {
err = walk(opt, opCH, path)
err = walk(opt, opCH, path, 1)
if err != nil {
close(opCH)
checkError(err)
Expand Down Expand Up @@ -783,7 +789,10 @@ func ignore(opt *Options, path string) bool {
return true
}

func walk(opt *Options, opCh chan<- operation, path string) error {
func walk(opt *Options, opCh chan<- operation, path string, depth int) error {
if opt.MaxDepth > 0 && depth > opt.MaxDepth {
return nil
}
_, err := ioutil.ReadFile(path)
// it's a file
if err == nil {
Expand Down Expand Up @@ -816,27 +825,29 @@ func walk(opt *Options, opCh chan<- operation, path string) error {
}
}

for _, filename := range _files {
if ignore(opt, filename) {
continue
}
fileFullPath := filepath.Join(path, filename)
if ok, op := checkOperation(opt, fileFullPath); ok {
opCh <- op
if !opt.OnlyDir {
for _, filename := range _files {
if ignore(opt, filename) {
continue
}
fileFullPath := filepath.Join(path, filename)
if ok, op := checkOperation(opt, fileFullPath); ok {
opCh <- op
}
}
}

// sub directory
for _, filename := range _dirs {
fileFullPath := filepath.Join(path, filename)
if opt.Recursive {
err := walk(opt, opCh, fileFullPath)
err := walk(opt, opCh, fileFullPath, depth+1)
if err != nil {
return err
}
}
// rename directories
if opt.IncludingDir && !ignore(opt, filename) {
if (opt.OnlyDir || opt.IncludingDir) && !ignore(opt, filename) {
if ok, op := checkOperation(opt, fileFullPath); ok {
opCh <- op
}
Expand Down
Empty file modified packaging.sh
100755 → 100644
Empty file.

0 comments on commit e4253ed

Please sign in to comment.