-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
182274e
commit 8439770
Showing
4 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
## [1.0.0] - 2021-10-13 | ||
### Added | ||
- Initial Version | ||
|
||
[1.0.0]: https://github.com/robrbecker/replace/releases/tag/1.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,46 @@ | ||
# replace | ||
Easy to use cross-platform regex replace command line util | ||
|
||
### Installing | ||
`pub global activate replace` | ||
|
||
or more advanced install | ||
- clone the project | ||
- `pub get` | ||
- `dart compile exe bin/replace.dart -o replace` | ||
- Place the `replace` executable in your path | ||
|
||
### Running | ||
`replace <regexp> <replacement> <glob>` | ||
|
||
Regexes and globs are Dart style | ||
Glob Syntax: https://pub.dev/packages/glob#syntax | ||
|
||
The replacement may contain references to the capture groups in regexp using a backslash followed by the group number. Backslashes not followed by a number return the character immediately following them. | ||
|
||
Examples: | ||
|
||
Simple strings and filename | ||
`replace word newword filename` | ||
|
||
Regex and glob (w/ quotes around arguments) | ||
`replace "(war).*(worlds)" "\1 of the monkeys" **` | ||
|
||
### Developing | ||
This project uses cider to maintain the changelog. | ||
|
||
`cider log <type> <description>` | ||
type is one of: added, changed, deprecated, removed, fixed, security | ||
|
||
Examples: | ||
``` | ||
cider log changed 'New turbo V6 engine installed' | ||
cider log added 'Support for rocket fuel and kerosene' | ||
cider log fixed 'Wheels falling off sporadically' | ||
``` | ||
|
||
When ready to release just run | ||
|
||
`cider bump <part>` (part is major, minor, patch) | ||
and | ||
`cider release` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import 'dart:io'; | ||
import 'package:cli_script/cli_script.dart'; | ||
import 'package:file/local.dart'; | ||
import 'package:glob/glob.dart'; | ||
|
||
void main(List<String> args) async { | ||
var usage = 'replace <regexp> <replacement> <glob>'; | ||
if (args.length < 3) { | ||
print(usage); | ||
return; | ||
} | ||
var regexp = args[0]; | ||
var replacement = args[1]; | ||
var glob = Glob(args[2]); | ||
|
||
var files = await glob | ||
.listFileSystem(const LocalFileSystem()).toList(); | ||
var transformer = replace(regexp, replacement, all: true, caseSensitive: false); | ||
|
||
for (var f in files) { | ||
print(f.path); | ||
var contents = (await asStream(f).transform<String>(transformer).toList()).first; | ||
File(f.path).writeAsStringSync(contents); | ||
} | ||
} | ||
|
||
Stream<String> asStream(FileSystemEntity f) async* { | ||
yield await File(f.path).readAsString(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: replace | ||
version: 1.0.0 | ||
description: An easy to use cross-platform regex replace command line util. | ||
repository: https://github.com/robrbecker/replace | ||
|
||
environment: | ||
sdk: '>=2.12.0 <3.0.0' | ||
|
||
dependencies: | ||
args: ^2.0.0 | ||
cli_script: ^0.2.3 | ||
file: ^6.0.0 | ||
glob: ^2.0.0 | ||
|
||
executables: | ||
replace: | ||
|
||
cider: | ||
link_template: | ||
tag: https://github.com/robrbecker/replace/releases/tag/%tag% | ||
diff: https://github.com/robrbecker/replace/compare/%from%...%to% |