all repos — fae @ 7fd37a67698bbc116d025a5e1da491680737e744

A minuscule find and edit utility.

Implemented --test flag.
h3rald h3rald@h3rald.com
Sun, 24 May 2015 12:34:36 +0200
commit

7fd37a67698bbc116d025a5e1da491680737e744

parent

012cbe7730f0421db92b3c7eb4bf8bb5dc9f2dd7

1 files changed, 5 insertions(+), 2 deletions(-)

jump to
M far.nimfar.nim

@@ -14,6 +14,7 @@ filter: string

substitute: string directory: string apply: bool + test: bool system.addQuitProc(resetAttributes)

@@ -104,7 +105,7 @@ return confirm(msg)

## Processing Options -var options = FarOptions(regex: nil, recursive: false, filter: nil, substitute: nil, directory: ".", apply: false) +var options = FarOptions(regex: nil, recursive: false, filter: nil, substitute: nil, directory: ".", apply: false, test: false) for kind, key, val in getOpt(): case kind:

@@ -125,6 +126,8 @@ of "directory", "d":

options.directory = val of "apply", "a": options.apply = true + of "test", "t": + options.test = true else: discard else:

@@ -171,7 +174,7 @@ displayMatch(contents, matchstart, matchend, fgRed)

var replacement = contents.replace(options.regex, options.substitute, matchstart) var new_offset = options.substitute.len-(matchend-matchstart+1) displayMatch(replacement, matchstart, matchend+new_offset, fgYellow) - if options.apply or confirm("Confirm replacement? [Y/n] "): + if (not options.test) and (options.apply or confirm("Confirm replacement? [Y/n] ")): f.writefile(replacement) contents = f.readFile() offset = offset + new_offset