Skip to content

Commit

Permalink
Update date variables and bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoisaiah committed Mar 11, 2021
1 parent 418f2f8 commit 836e32c
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 6 deletions.
59 changes: 55 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ AUTHOR:
Ayooluwa Isaiah <[email protected]>
VERSION:
v1.1.1
v1.2.1
FLAGS:
--find string, -f string Search string or regular expression.
Expand All @@ -144,6 +144,9 @@ FLAGS:
--help, -h show help (default: false)
--version, -v print the version (default: false)
DOCUMENTATION:
https://github.com/ayoisaiah/f2#examples
WEBSITE:
https://github.com/ayoisaiah/f2
```
Expand Down Expand Up @@ -416,10 +419,12 @@ $ f2 -f '-' -r '/' -x

### Use a variable

The replacement string can contain the following variables that will be replaced with their corresponding value.
The replacement string can contain several variables will be replaced with their corresponding value.

#### File name and extension

- `{{f}}` is the original filename (excluding the extension)
- `{{ext}}` is the file extension
- `{{f}}` is the original filename (excluding the extension)
- `{{ext}}` is the file extension

This is helpful if you want to add a prefix or a suffix to a set of files:

Expand All @@ -445,6 +450,52 @@ $ f2 -r 'journal_{{f}}{{ext}}' # prefix
+-------------------+---------------------------+--------+
```

#### Date variables

The time attributes of a file can be used in the replacement string. F2 provides variables that enable you to access the file creation time, modification time, access time and more.

- `ctime`: The time at which file metadata was changed. (Windows, macOS, and Linux).
- `btime`: File birth time (Windows and macOS).
- `atime`: The last time the file was accessed or read (Windows, macOS and Linux).
- `mtime`: Time of last file modification (Windows, macOS and Linux).
- `now`: The current time.

The above variables must be combined with any of the following date tokens:

| Token | Explanation | Output |
| ------------- | ------------- |
| YYYY | Year represented by a full four digits | 1970 1971 ... 2029 2030 |
| YY | Year represented only by the last two digits | 70 71 ... 29 30 |
| MMMM | Name of the month | January February ... November December |
| MMM | Abbreviated name of the month | Jan Feb ... Nov Dec |
| MM | Month as digits with leading zeros for single-digit months | 01 02 ... 11 12 |
| M | Month as digits without leading zeros for single-digit months | 1 2 ... 11 12 |
| DDDD | Name of the day of the week | Monday Tuesday ... Saturday Sunday |
| DDD | Abbreviated name of the day of the week | Mon Tue ... Sat Sun |
| DD | Day of the week as digit with leading zeros | 01 02 ... 06 07 |
| D | Day of the week as digit without leading zeros | 1 2 ... 6 7 |
| H | 24 Hours clock | 01 02 ... 22 23 |
| hh | Hours with leading zeros for single-digit hours | 01 02 ... 11 12 |
| h | Hours without leading zeros for single-digit hours | 1 2 ... 11 12 |
| mm | Minutes with leading zeros for single-digit minutes | 01 02 ... 58 59 |
| m | Minutes without leading zeros for single-digit minutes | 1 2 ... 58 59 |
| ss | Seconds with leading zeros for single-digit seconds | 01 02 ... 58 59 |
| s | Seconds without leading zeros for single-digit seconds | 1 2 ... 58 59 |
| A | AM PM | AM PM |
| a | am pm | am pm |

**Example**

```bash
$ f2 -f 'screenshot' -r '{{mtime.MMM}}-{{mtime.DD}}-{{mtime.YYYY}}-screenshot'
+----------------+----------------------------+--------+
| INPUT | OUTPUT | STATUS |
+----------------+----------------------------+--------+
| screenshot.jpg | Nov-08-2020-screenshot.jpg | ok |
| screenshot.png | Mar-04-2021-screenshot.png | ok |
+----------------+----------------------------+--------+
```

*More variables coming soon*

### Conflict detection
Expand Down
5 changes: 4 additions & 1 deletion app.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ VERSION:
FLAGS:{{range .VisibleFlags}}
{{.}}{{end}}{{end}}
DOCUMENTATION:
https://github.com/ayoisaiah/f2#examples
WEBSITE:
https://github.com/ayoisaiah/f2
`
Expand Down Expand Up @@ -71,7 +74,7 @@ func GetApp() *cli.App {
},
Usage: "F2 is a command-line tool for batch renaming multiple files and directories quickly and safely",
UsageText: "FLAGS [OPTIONS] [PATHS...]",
Version: "v1.2.0",
Version: "v1.2.1",
EnableBashCompletion: true,
Flags: []cli.Flag{
&cli.StringFlag{
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/urfave/cli/v2 v2.2.0 h1:JTTnM6wKzdA0Jqodd966MVj4vWbbquZykeX1sKbe2C4=
github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
3 changes: 2 additions & 1 deletion operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ var dateTokens = map[string]string{
"DDD": "Mon",
"DD": "02",
"D": "2",
"hh": "15",
"H": "15",
"hh": "03",
"h": "3",
"mm": "04",
"m": "4",
Expand Down

0 comments on commit 836e32c

Please sign in to comment.