🔧 Update script metadata and enhance howto.ts with command extraction and execution logic
This commit is contained in:
@@ -153,12 +153,12 @@
|
|||||||
},
|
},
|
||||||
"howto.ts": {
|
"howto.ts": {
|
||||||
"script_name": "howto.ts",
|
"script_name": "howto.ts",
|
||||||
"script_length": 1225,
|
"script_length": 2121,
|
||||||
"script_sha256": "97b7f0efd97b774c70000a5cb56f9115df0e9473cc2018b0404f7556bdba0e83",
|
"script_sha256": "0c78b2ca3729ffb4fbe92c46f8bc15e62dd9224670db5cc0fe9efccf29759958",
|
||||||
"script_full_url": "https://git.hatter.ink/hatter/ts-scripts/raw/branch/main/single-scripts/howto.ts",
|
"script_full_url": "https://git.hatter.ink/hatter/ts-scripts/raw/branch/main/single-scripts/howto.ts",
|
||||||
"single_script_file": true,
|
"single_script_file": true,
|
||||||
"publish_time": 1775973075081,
|
"publish_time": 1775973075081,
|
||||||
"update_time": 1775973377013
|
"update_time": 1775980874679
|
||||||
},
|
},
|
||||||
"init-cheatsheet.ts": {
|
"init-cheatsheet.ts": {
|
||||||
"script_name": "init-cheatsheet.ts",
|
"script_name": "init-cheatsheet.ts",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env runts -- --allow-all
|
#!/usr/bin/env runts -- --allow-all
|
||||||
|
|
||||||
import {parseArgs} from "jsr:@std/cli/parse-args";
|
import {parseArgs} from "jsr:@std/cli/parse-args";
|
||||||
import {exit, log, ProcessBar,} from "https://script.hatter.ink/@67/deno-commons-mod.ts";
|
import {execCommandShell, exit, log, ProcessBar, term,} from "https://script.hatter.ink/@67/deno-commons-mod.ts";
|
||||||
import {howto} from "https://script.hatter.ink/@1/deno-ai-mod.ts";
|
import {howto} from "https://script.hatter.ink/@1/deno-ai-mod.ts";
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
@@ -33,6 +33,38 @@ howto.ts 'MESSAGE' - generate command line for MESSAGE
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
log.success(`AI howto command line message: \n${summary}`);
|
log.success(`AI howto command line message: \n${summary}`);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const commandLine = extractCommand(summary);
|
||||||
|
console.log(
|
||||||
|
"Command line: ",
|
||||||
|
term.auto(`[green][[[${commandLine}]]][/]`),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (confirm("Execute this command?")) {
|
||||||
|
const status = await execCommandShell("sh", ["-c", commandLine]);
|
||||||
|
exit(status);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log.error("Extract command line failed", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function extractCommand(summary: string): string {
|
||||||
|
const lines = summary.split(/\r?\n/);
|
||||||
|
const sb = [];
|
||||||
|
let inCode = false;
|
||||||
|
for (const line of lines) {
|
||||||
|
if (inCode) {
|
||||||
|
if (line.startsWith("```")) {
|
||||||
|
return sb.join("\n");
|
||||||
|
}
|
||||||
|
sb.push(line);
|
||||||
|
} else if (line.startsWith("```")) {
|
||||||
|
inCode = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new Error("Command line not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
main().catch((err) => {
|
main().catch((err) => {
|
||||||
@@ -40,5 +72,5 @@ main().catch((err) => {
|
|||||||
process.exit(0);
|
process.exit(0);
|
||||||
}).then(() => process.exit(0));
|
}).then(() => process.exit(0));
|
||||||
|
|
||||||
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260412T135613+08:00.MEUCIQDbJGYgxtAv1d6Vrmyj
|
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260412T160105+08:00.MEQCIGSMGJYgv+Am7EZUBj9N
|
||||||
// vQDEJGFUuZuH1UQOYQhWRzN69wIgS8tw92nMpF5TLQy/qS4uk7w7d8iY8rmT6DR+V3jg0lM=
|
// B1c1seTE1jc48Z7CZiKn0d23AiAdmw6UTSXRMH/BQKbhuVoFs6GiBo783QxnCXYT4TWf8A==
|
||||||
|
|||||||
Reference in New Issue
Block a user