diff --git a/libraries/deno-ai-mod.ts b/libraries/deno-ai-mod.ts index 6211a29..f3afd01 100644 --- a/libraries/deno-ai-mod.ts +++ b/libraries/deno-ai-mod.ts @@ -18,6 +18,7 @@ export async function howto(message: string): Promise { body: new URLSearchParams({ "message": message, }), + timeoutMillis: 30_000, }, ); if (response.status != 200) { @@ -49,6 +50,7 @@ export async function summarizeGitStatusDiff(): Promise { "gitStatus": gitStatus, "gitDiff": gitDiff, }), + timeoutMillis: 30_000, }, ); if (response.status != 200) { diff --git a/script-meta-v2.json b/script-meta-v2.json index 9ea9982..036644d 100644 --- a/script-meta-v2.json +++ b/script-meta-v2.json @@ -153,12 +153,12 @@ }, "howto.ts": { "script_name": "howto.ts", - "script_length": 3711, - "script_sha256": "17a15529aaffceb08fddaf8a073a66b26cf1ce7f296b6e23472203bb993604fe", + "script_length": 4094, + "script_sha256": "b1c77486ac714c346fea5f3a8df733b142404baee0d9421d6c05de4c765faae3", "script_full_url": "https://git.hatter.ink/hatter/ts-scripts/raw/branch/main/single-scripts/howto.ts", "single_script_file": true, "publish_time": 1775973075081, - "update_time": 1776004581240 + "update_time": 1776005585038 }, "init-cheatsheet.ts": { "script_name": "init-cheatsheet.ts", diff --git a/single-scripts/howto.ts b/single-scripts/howto.ts index 2b918b2..e926c14 100755 --- a/single-scripts/howto.ts +++ b/single-scripts/howto.ts @@ -1,8 +1,14 @@ #!/usr/bin/env runts -- --allow-all -import {parseArgs} from "jsr:@std/cli/parse-args"; -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 { parseArgs } from "jsr:@std/cli/parse-args"; +import { + execCommandShell, + exit, + log, + ProcessBar, + term, +} from "https://script.hatter.ink/@67/deno-commons-mod.ts"; +import { howto } from "https://script.hatter.ink/@2/deno-ai-mod.ts"; async function main() { const flags = parseArgs(Deno.args, { @@ -42,10 +48,14 @@ howto.ts [-N|--no-exec] 'MESSAGE' - generate command line for MESSAGE if (!noExec) { try { const commandLines = extractCommand(summary); - console.log( - "Found command lines: ", - term.auto(`[green][[[${commandLines}]]][/]`), - ); + if (commandLines.length == 1) { + log.success( + "Found command line: ", + term.auto(`[green][[[${commandLines}]]][/]`), + ); + } else { + log.success(`Found ${commandLines.length} commands`); + } if (commandLines.length == 1) { if (confirm("Execute this command?")) { @@ -57,8 +67,11 @@ howto.ts [-N|--no-exec] 'MESSAGE' - generate command line for MESSAGE ); } } else { + const colors = ["red", "green", "blue"]; for (const [i, command] of commandLines.entries()) { - console.log(`# ${i}: ${command}`); + console.log(term.auto( + `[${colors[i % 3]}][[[# ${i}: ${command}]]][/]`, + )); } const selectCommandLineIndex = parseInt( prompt( @@ -92,15 +105,16 @@ howto.ts [-N|--no-exec] 'MESSAGE' - generate command line for MESSAGE function extractCommand(summary: string): string[] { const lines = summary.split(/\r?\n/); const codeBlocks: string[] = []; - const sb: string[] = []; + let codeBlock: string[] = []; let inCode = false; for (const line of lines) { if (inCode) { if (line.startsWith("```")) { - codeBlocks.push(sb.join("\n")); + codeBlocks.push(codeBlock.join("\n")); + codeBlock = []; inCode = false; } else { - sb.push(line); + codeBlock.push(line); } } else if (line.startsWith("```")) { inCode = true; @@ -117,5 +131,5 @@ main().catch((err) => { process.exit(0); }).then(() => process.exit(0)); -// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260412T223617+08:00.MEUCIQDnSaL6GY90yaRpt8ma -// aWHXc9cHuVgrg7BrziUQzMamLQIgflN7/NxONwn0iqrPiCdOlbAcWBdVw47XlyU5bwNgA20= +// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260412T225301+08:00.MEQCIEPTb4Mwqih4QKV7EULz +// SAoBxv7KfLZjH14w5EQrdOKHAiAkl/cxcehBt/Lot9ZLfYsJQfPSzZKBkDwy/RWjxsjyhQ==