Skip to content

Commit

Permalink
add new option -a to list absolute path
Browse files Browse the repository at this point in the history
  • Loading branch information
shenwei356 committed Jan 18, 2018
1 parent 476e19d commit 46f669e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 18 deletions.
41 changes: 28 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@

#### Method 1: Download binaries

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

***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.5.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.5.0/brename_linux_386.tar.gz)
Linux |**64-bit**|[**brename_linux_amd64.tar.gz**](https://github.com/shenwei356/brename/releases/download/v2.5.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.5.0/brename_linux_amd64.tar.gz)
OS X |32-bit |[brename_darwin_386.tar.gz](https://github.com/shenwei356/brename/releases/download/v2.5.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.5.0/brename_darwin_386.tar.gz)
OS X |**64-bit**|[**brename_darwin_amd64.tar.gz**](https://github.com/shenwei356/brename/releases/download/v2.5.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.5.0/brename_darwin_amd64.tar.gz)
Windows|32-bit |[brename_windows_386.exe.tar.gz](https://github.com/shenwei356/brename/releases/download/v2.5.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.5.0/brename_windows_386.exe.tar.gz)
Windows|**64-bit**|[**brename_windows_amd64.exe.tar.gz**](https://github.com/shenwei356/brename/releases/download/v2.5.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.5.0/brename_windows_amd64.exe.tar.gz)
Linux |32-bit |[brename_linux_386.tar.gz](https://github.com/shenwei356/brename/releases/download/v2.5.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.5.1/brename_linux_386.tar.gz)
Linux |**64-bit**|[**brename_linux_amd64.tar.gz**](https://github.com/shenwei356/brename/releases/download/v2.5.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.5.1/brename_linux_amd64.tar.gz)
OS X |32-bit |[brename_darwin_386.tar.gz](https://github.com/shenwei356/brename/releases/download/v2.5.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.5.1/brename_darwin_386.tar.gz)
OS X |**64-bit**|[**brename_darwin_amd64.tar.gz**](https://github.com/shenwei356/brename/releases/download/v2.5.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.5.1/brename_darwin_amd64.tar.gz)
Windows|32-bit |[brename_windows_386.exe.tar.gz](https://github.com/shenwei356/brename/releases/download/v2.5.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.5.1/brename_windows_386.exe.tar.gz)
Windows|**64-bit**|[**brename_windows_amd64.exe.tar.gz**](https://github.com/shenwei356/brename/releases/download/v2.5.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.5.1/brename_windows_amd64.exe.tar.gz)


Just [download](https://github.com/shenwei356/brename/releases) compressed
Expand Down Expand Up @@ -95,7 +95,7 @@ And then:
```
brename -- a practical cross-platform command-line tool for safely batch renaming files/directories via regular expression
Version: 2.5.0
Version: 2.5.1
Author: Wei Shen <[email protected]>
Expand All @@ -115,7 +115,7 @@ Special replacement symbols:
n can be specified by flag -I/--key-capt-idx (default: 1)
Usage:
brename [flags]
brename [flags]
Examples:
1. dry run and showing potential dangerous operations
Expand Down Expand Up @@ -153,6 +153,7 @@ Flags:
-m, --key-miss-repl string replacement for key with no corresponding value
-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
-p, --pattern string search pattern (regular expression)
-R, --recursive rename recursively
-r, --replacement string 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}"
Expand Down Expand Up @@ -350,9 +351,23 @@ Take a directory for example:
└── b
└── c.txt

1. only list paths that match pattern (`-l`)

brename -i -f '.docx?$' -p . -R -l
1. only list paths that match pattern (`-l` and `-a`)

$ brename -p '.gz$' -R -l
binaries/brename_darwin_386.tar.gz
binaries/brename_darwin_amd64.tar.gz
binaries/brename_linux_386.tar.gz
binaries/brename_linux_amd64.tar.gz
binaries/brename_windows_386.exe.tar.gz
binaries/brename_windows_amd64.exe.tar.gz
$ brename -p '.gz$' -R -l
/home/shenwei/project/src/github.com/shenwei356/brename/binaries/brename_darwin_386.tar.gz
/home/shenwei/project/src/github.com/shenwei356/brename/binaries/brename_darwin_amd64.tar.gz
/home/shenwei/project/src/github.com/shenwei356/brename/binaries/brename_linux_386.tar.gz
/home/shenwei/project/src/github.com/shenwei356/brename/binaries/brename_linux_amd64.tar.gz
/home/shenwei/project/src/github.com/shenwei356/brename/binaries/brename_windows_386.exe.tar.gz
/home/shenwei/project/src/github.com/shenwei356/brename/binaries/brename_windows_amd64.exe.tar.gz


## Real-world examples
Expand Down
22 changes: 17 additions & 5 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.5.0"
var version = "2.5.1"
var app = "brename"

// Options is the struct containing all global options
Expand All @@ -63,7 +63,9 @@ type Options struct {
ExcludeFilters []string
IncludeFilterRes []*regexp.Regexp
ExcludeFilterRes []*regexp.Regexp
ListPath bool

ListPath bool
ListAbsPath bool

ReplaceWithNR bool
StartNum int
Expand Down Expand Up @@ -190,7 +192,9 @@ func getOptions(cmd *cobra.Command) *Options {
IncludeFilterRes: infilterRes,
ExcludeFilters: infilters,
ExcludeFilterRes: exfilterRes,
ListPath: getFlagBool(cmd, "list"),

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

ReplaceWithNR: replaceWithNR,
StartNum: getFlagNonNegativeInt(cmd, "start-num"),
Expand Down Expand Up @@ -230,6 +234,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().BoolP("list-abs", "a", false, `list absolute path, using along with -l/--list`)

RootCmd.Flags().StringP("kv-file", "k", "",
`tab-delimited key-value file for replacing key with value when using "{kv}" in -r (--replacement)`)
Expand Down Expand Up @@ -419,11 +424,19 @@ Special replacement symbols:

var hasErr bool
var n, nErr int
var outPath string
var err error

go func() {
for op := range opCH {
if opt.ListPath {
fmt.Println(op.source)
if opt.ListAbsPath {
outPath, err = filepath.Abs(op.source)
checkError(err)
} else {
outPath = op.source
}
fmt.Println(outPath)
continue
}
if int(op.code) >= opt.Verbose {
Expand Down Expand Up @@ -453,7 +466,6 @@ Special replacement symbols:
done <- 1
}()

var err error
for _, path := range getFileList(args) {
err = walk(opt, opCH, path)
if err != nil {
Expand Down

0 comments on commit 46f669e

Please sign in to comment.