MCPcopy Create free account
hub / github.com/pbakaus/impeccable / shellPythonWriteDestination

Function shellPythonWriteDestination

skill/scripts/hook-before-edit.mjs:186–206  ·  view source on GitHub ↗
(command)

Source from the content-addressed store, hash-verified

184}
185
186function shellPythonWriteDestination(command) {
187 if (!/\bpython(?:3)?\b/.test(command || '')) return '';
188 const directPath = firstMatch(command, /(?:^|[^\w.])(?:pathlib\.)?Path\(\s*(["'])(.*?)\1\s*\)\s*\.write_text\s*\(/);
189 if (directPath) return directPath;
190
191 const pathsByVar = new Map();
192 const assignmentRe = /\b([A-Za-z_]\w*)\s*=\s*(?:pathlib\.)?Path\(\s*(["'])(.*?)\2\s*\)/g;
193 let assignment;
194 while ((assignment = assignmentRe.exec(command))) {
195 pathsByVar.set(assignment[1], assignment[3]);
196 }
197
198 const writeVarRe = /\b([A-Za-z_]\w*)\.write_text\s*\(/g;
199 let writeVar;
200 while ((writeVar = writeVarRe.exec(command))) {
201 const candidate = pathsByVar.get(writeVar[1]);
202 if (candidate) return candidate;
203 }
204
205 return firstMatch(command, /\bopen\(\s*(["'])(.*?)\1\s*,\s*(["'])[wax](?:\+)?b?\3/);
206}
207
208function firstMatch(value, re) {
209 const match = String(value || '').match(re);

Callers 1

shellWriteDestinationFunction · 0.70

Calls 1

firstMatchFunction · 0.70

Tested by

no test coverage detected