⚙️ Enhance script functionality with timeout settings, improved command handling, and updated dependencies
This commit is contained in:
@@ -18,6 +18,7 @@ export async function howto(message: string): Promise<string> {
|
|||||||
body: new URLSearchParams({
|
body: new URLSearchParams({
|
||||||
"message": message,
|
"message": message,
|
||||||
}),
|
}),
|
||||||
|
timeoutMillis: 30_000,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
if (response.status != 200) {
|
if (response.status != 200) {
|
||||||
@@ -49,6 +50,7 @@ export async function summarizeGitStatusDiff(): Promise<string> {
|
|||||||
"gitStatus": gitStatus,
|
"gitStatus": gitStatus,
|
||||||
"gitDiff": gitDiff,
|
"gitDiff": gitDiff,
|
||||||
}),
|
}),
|
||||||
|
timeoutMillis: 30_000,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
if (response.status != 200) {
|
if (response.status != 200) {
|
||||||
|
|||||||
+3
-3
@@ -153,12 +153,12 @@
|
|||||||
},
|
},
|
||||||
"howto.ts": {
|
"howto.ts": {
|
||||||
"script_name": "howto.ts",
|
"script_name": "howto.ts",
|
||||||
"script_length": 3711,
|
"script_length": 4094,
|
||||||
"script_sha256": "17a15529aaffceb08fddaf8a073a66b26cf1ce7f296b6e23472203bb993604fe",
|
"script_sha256": "b1c77486ac714c346fea5f3a8df733b142404baee0d9421d6c05de4c765faae3",
|
||||||
"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": 1776004581240
|
"update_time": 1776005585038
|
||||||
},
|
},
|
||||||
"init-cheatsheet.ts": {
|
"init-cheatsheet.ts": {
|
||||||
"script_name": "init-cheatsheet.ts",
|
"script_name": "init-cheatsheet.ts",
|
||||||
|
|||||||
+27
-13
@@ -1,8 +1,14 @@
|
|||||||
#!/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 {execCommandShell, exit, log, ProcessBar, term,} from "https://script.hatter.ink/@67/deno-commons-mod.ts";
|
import {
|
||||||
import {howto} from "https://script.hatter.ink/@1/deno-ai-mod.ts";
|
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() {
|
async function main() {
|
||||||
const flags = parseArgs(Deno.args, {
|
const flags = parseArgs(Deno.args, {
|
||||||
@@ -42,10 +48,14 @@ howto.ts [-N|--no-exec] 'MESSAGE' - generate command line for MESSAGE
|
|||||||
if (!noExec) {
|
if (!noExec) {
|
||||||
try {
|
try {
|
||||||
const commandLines = extractCommand(summary);
|
const commandLines = extractCommand(summary);
|
||||||
console.log(
|
if (commandLines.length == 1) {
|
||||||
"Found command lines: ",
|
log.success(
|
||||||
term.auto(`[green][[[${commandLines}]]][/]`),
|
"Found command line: ",
|
||||||
);
|
term.auto(`[green][[[${commandLines}]]][/]`),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
log.success(`Found ${commandLines.length} commands`);
|
||||||
|
}
|
||||||
|
|
||||||
if (commandLines.length == 1) {
|
if (commandLines.length == 1) {
|
||||||
if (confirm("Execute this command?")) {
|
if (confirm("Execute this command?")) {
|
||||||
@@ -57,8 +67,11 @@ howto.ts [-N|--no-exec] 'MESSAGE' - generate command line for MESSAGE
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
const colors = ["red", "green", "blue"];
|
||||||
for (const [i, command] of commandLines.entries()) {
|
for (const [i, command] of commandLines.entries()) {
|
||||||
console.log(`# ${i}: ${command}`);
|
console.log(term.auto(
|
||||||
|
`[${colors[i % 3]}][[[# ${i}: ${command}]]][/]`,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
const selectCommandLineIndex = parseInt(
|
const selectCommandLineIndex = parseInt(
|
||||||
prompt(
|
prompt(
|
||||||
@@ -92,15 +105,16 @@ howto.ts [-N|--no-exec] 'MESSAGE' - generate command line for MESSAGE
|
|||||||
function extractCommand(summary: string): string[] {
|
function extractCommand(summary: string): string[] {
|
||||||
const lines = summary.split(/\r?\n/);
|
const lines = summary.split(/\r?\n/);
|
||||||
const codeBlocks: string[] = [];
|
const codeBlocks: string[] = [];
|
||||||
const sb: string[] = [];
|
let codeBlock: string[] = [];
|
||||||
let inCode = false;
|
let inCode = false;
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
if (inCode) {
|
if (inCode) {
|
||||||
if (line.startsWith("```")) {
|
if (line.startsWith("```")) {
|
||||||
codeBlocks.push(sb.join("\n"));
|
codeBlocks.push(codeBlock.join("\n"));
|
||||||
|
codeBlock = [];
|
||||||
inCode = false;
|
inCode = false;
|
||||||
} else {
|
} else {
|
||||||
sb.push(line);
|
codeBlock.push(line);
|
||||||
}
|
}
|
||||||
} else if (line.startsWith("```")) {
|
} else if (line.startsWith("```")) {
|
||||||
inCode = true;
|
inCode = true;
|
||||||
@@ -117,5 +131,5 @@ main().catch((err) => {
|
|||||||
process.exit(0);
|
process.exit(0);
|
||||||
}).then(() => process.exit(0));
|
}).then(() => process.exit(0));
|
||||||
|
|
||||||
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260412T223617+08:00.MEUCIQDnSaL6GY90yaRpt8ma
|
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260412T225301+08:00.MEQCIEPTb4Mwqih4QKV7EULz
|
||||||
// aWHXc9cHuVgrg7BrziUQzMamLQIgflN7/NxONwn0iqrPiCdOlbAcWBdVw47XlyU5bwNgA20=
|
// SAoBxv7KfLZjH14w5EQrdOKHAiAkl/cxcehBt/Lot9ZLfYsJQfPSzZKBkDwy/RWjxsjyhQ==
|
||||||
|
|||||||
Reference in New Issue
Block a user