https://github.com/hash-bang/cli-foreachfile
Simple CLI utility to recursively execute a command for each matching file
https://github.com/hash-bang/cli-foreachfile
Last synced: 5 months ago
JSON representation
Simple CLI utility to recursively execute a command for each matching file
- Host: GitHub
- URL: https://github.com/hash-bang/cli-foreachfile
- Owner: hash-bang
- Created: 2015-03-22T01:53:09.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2020-05-14T03:55:39.000Z (about 5 years ago)
- Last Synced: 2024-12-25T16:02:48.708Z (5 months ago)
- Language: JavaScript
- Homepage:
- Size: 29.3 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
ForEachFile
===========
Simple CLI utility to recursively execute a command for each matching file.Examples:
```
# Visit each .tar file (setting the directory to its location) and untar:
> each '**/*.tar' -- tar xvf %f# Convert all .jpg images to .png
> each '**/*.jpg' -- convert %b.jpg %b.png
```Usage
-----
```
Usage: each [glob] --Options:
-V, --version output the version number
-c, --command Explicitally specify the command to run
-d, --dir Change into each files directory before executing
-n, --dry-run Do not run anything, instead show what would be run
-implies `-v`
-g, --glob Explicitally specify the glob to use
-l, --log Log text before each execution (default:
"${colors.blue('[File]')} %r")
-p, --parallel Specify the number of processes to run in parallel
(default: 1)
-v, --verbose Be verbose
-h, --help output usage informationNotes:
* Command arguments and log output can use ES6 templates or simple percentage prefix charactersExamples:
# List all basenames from this directory recursively
each '**/*' -- echo %f# Convert all JPG images into PNG
each '**/*.jpg' -- convert %b.jpg %b.png
```Installation
------------
Install globally with NPM:```
sudo npm install -g cli-foreachfile
```Command expansion
-----------------
Commands can be written in a variety of ways. Each of the below tokens gets expanded into the value shown.| Category | Token | Example | Description |
|----------------|-----------------|----------------------------|----------------------------------|
| File | `%b` | `myfile.foo` | File name |
| " | `%f` | `myfile.foo` | File name |
| " | `{{name}}` | `myfile.foo` | File name without extension |
| " | `{{base}}` | `myfile` | File name |
| " | `{{basename}}` | `myfile` | File name |
| " | `{{relative}}` | `./myfile.foo`, | File name relative to PWD |
| " | `%r` | `./myfile.foo`, | File name relative to PWD |
| File Info | `%e` | `foo` | File extension |
| " | `{{ext}}` | `foo` | File extension |
| Directory | `%d` | `/foo/bar/baz/myfile.foo` | Relative dir to pwd |
| " | `{{dir}}` | `/foo/bar/baz` | The dir portion of the full path |
| " | `{{dirname}}` | `/foo/bar/baz` | The dir portion of the full path |
| Full Path | `%p` | `/foo/bar/baz/myfile.foo` | Full File path |
| " | `{{path}}` | `/foo/bar/baz/myfile.foo` | Full File path |
| Utilities | `{{colors}}` | | [Chalk](https://github.com/chalk/chalk) Instance |
| | `{{path}}` | | [Path](https://nodejs.org/api/path.html) NodeJS Core Instance |