🔧 Update script metadata and enhance command extraction logic in howto.ts
This commit is contained in:
+3
-3
@@ -153,12 +153,12 @@
|
|||||||
},
|
},
|
||||||
"howto.ts": {
|
"howto.ts": {
|
||||||
"script_name": "howto.ts",
|
"script_name": "howto.ts",
|
||||||
"script_length": 2337,
|
"script_length": 3597,
|
||||||
"script_sha256": "778267bdb0d5005951090f8e3dc608da507343b06f4c1cc507b9ea797bed64ea",
|
"script_sha256": "741b5f399a75438f7f50f4a8118b8f3ab11a2e752d5056ca4d659f7a26b3333b",
|
||||||
"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": 1775981177228
|
"update_time": 1776004257105
|
||||||
},
|
},
|
||||||
"init-cheatsheet.ts": {
|
"init-cheatsheet.ts": {
|
||||||
"script_name": "init-cheatsheet.ts",
|
"script_name": "init-cheatsheet.ts",
|
||||||
|
|||||||
+50
-15
@@ -38,18 +38,47 @@ howto.ts 'MESSAGE' - generate command line for MESSAGE
|
|||||||
|
|
||||||
if (!noExec) {
|
if (!noExec) {
|
||||||
try {
|
try {
|
||||||
const commandLine = extractCommand(summary);
|
const commandLines = extractCommand(summary);
|
||||||
console.log(
|
console.log(
|
||||||
"Found command line: ",
|
"Found command lines: ",
|
||||||
term.auto(`[green][[[${commandLine}]]][/]`),
|
term.auto(`[green][[[${commandLines}]]][/]`),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (confirm("Execute this command?")) {
|
if (commandLines.length == 1) {
|
||||||
const status = await execCommandShell("sh", [
|
if (confirm("Execute this command?")) {
|
||||||
"-c",
|
exit(
|
||||||
commandLine,
|
await execCommandShell("sh", [
|
||||||
]);
|
"-c",
|
||||||
exit(status);
|
commandLines[0],
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (const [i, command] of commandLines.entries()) {
|
||||||
|
console.log(`# ${i}: ${command}`);
|
||||||
|
}
|
||||||
|
const selectCommandLineIndex = parseInt(
|
||||||
|
prompt(
|
||||||
|
"Please select the command line: ",
|
||||||
|
),
|
||||||
|
10,
|
||||||
|
);
|
||||||
|
if (
|
||||||
|
isNaN(selectCommandLineIndex) ||
|
||||||
|
selectCommandLineIndex < 0 ||
|
||||||
|
selectCommandLineIndex >= commandLines.length
|
||||||
|
) {
|
||||||
|
log.error(
|
||||||
|
`Bad command line index: ${selectCommandLineIndex}`,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
exit(
|
||||||
|
await execCommandShell("sh", [
|
||||||
|
"-c",
|
||||||
|
commandLines[0],
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log.error("Extract command line failed", e);
|
log.error("Extract command line failed", e);
|
||||||
@@ -57,20 +86,26 @@ howto.ts '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 sb = [];
|
const codeBlocks: string[] = [];
|
||||||
|
const sb: 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("```")) {
|
||||||
return sb.join("\n");
|
codeBlocks.push(sb.join("\n"));
|
||||||
|
inCode = false;
|
||||||
|
} else {
|
||||||
|
sb.push(line);
|
||||||
}
|
}
|
||||||
sb.push(line);
|
|
||||||
} else if (line.startsWith("```")) {
|
} else if (line.startsWith("```")) {
|
||||||
inCode = true;
|
inCode = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (codeBlocks.length > 0) {
|
||||||
|
return codeBlocks;
|
||||||
|
}
|
||||||
throw new Error("Command line not found");
|
throw new Error("Command line not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,5 +114,5 @@ main().catch((err) => {
|
|||||||
process.exit(0);
|
process.exit(0);
|
||||||
}).then(() => process.exit(0));
|
}).then(() => process.exit(0));
|
||||||
|
|
||||||
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260412T160614+08:00.MEUCIEasEUKkR/P0ESG/IpIB
|
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260412T223039+08:00.MEQCID73a9pHazHm+d5lLNqX
|
||||||
// 9turT2yM/EoOpSEwQdlz277qAiEAxCYPwvP563coKn1Ov3wI1icQR3Tesg2Hta0tdIn8f+8=
|
// w4YNafpy3qBHxKky88N9b4mCAiAnbuECrSICNjIK/onLSpWLc0MHjpdQyqGgL0B6pU24RQ==
|
||||||
|
|||||||
Reference in New Issue
Block a user