beetlebug▾
/

ztcl::code sub

Changes a text in each file of the tree.

ztcl::code sub OLD NEW ?PATH ...? ?-re? ?-w? ?-i? ?-glob G? ?-dry?

Description

OLD is literal unless -re, and NEW is literal unless -re, which gives NEW the & and \N of regsub. The files and the options -w, -i, and -glob are those of grep. The changes stay inside lines. -dry gives the changed lines and writes no file.

Returns

A line for each changed file with the count and the lines, and a last line with the counts.

Examples

Each example of this page runs after package require ztcl::code # A folder with three files, outside a git tree. set dir /tmp/ztcl-ref-code-[pid] file delete -force $dir file mkdir $dir cd $dir proc put {path text} { set ch [open $path w] puts -nonewline $ch $text close $ch } put a.zig "const std = @import(\"std\");\n\npub const Point = struct {\n x: i32,\n\n pub fn len(p: Point) i32 {\n return p.x;\n }\n};\n" put b.txt "one\ntwo\ntwo\n" put c.md "# Title\n\n## Part\n\ntext\n" # The tests use no model. set ::ztcl::code::backend {http ""} set ::ztcl::code::llm_url http://127.0.0.1:9/v1/chat/completions .

% ztcl::code sub two 2 . -dry
b.txt 2
  2: 2
  3: 2
2 changes in 1 file, no file written: -dry

% ztcl::code sub two 2 .
b.txt 2: lines 2, 3
2 changes in 1 file

Errors

% ztcl::code sub x
sub OLD NEW ?PATH ...? ?-re? ?-w? ?-i? ?-glob G? ?-dry?
-errorcode ZTCL CODE USAGE

Facts

Capability
file. A new interpreter does not have it until the host turns it on.
Tcl release
Tcl 9.1 and 8.6.
Since
ztcl 1.0.0-beta.2