1
Fork 0

Add an output directory option for scripts.

This commit is contained in:
Bauke 2023-03-19 14:26:08 +01:00
parent 73c0846b25
commit 220a3ce73a
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
1 changed files with 14 additions and 2 deletions

View File

@ -40,6 +40,7 @@ async function actionHandler(
const substituteMarkers = { const substituteMarkers = {
absoluteFile: "$absoluteFile", absoluteFile: "$absoluteFile",
filename: "$filename", filename: "$filename",
outWithFile: "$outWithFile",
}; };
for (const directory of options.directories) { for (const directory of options.directories) {
@ -73,6 +74,7 @@ async function actionHandler(
const substitutes = [ const substitutes = [
[substituteMarkers.absoluteFile, absoluteFile], [substituteMarkers.absoluteFile, absoluteFile],
[substituteMarkers.filename, file.name], [substituteMarkers.filename, file.name],
[substituteMarkers.outWithFile, `$out/${file.name}`],
]; ];
argumentLoop: argumentLoop:
@ -143,7 +145,13 @@ async function actionHandler(
if (options.outputScript) { if (options.outputScript) {
const defaultFilename = "bulk-run-script.zsh"; const defaultFilename = "bulk-run-script.zsh";
const { filename } = await prompt.prompt([ const { filename, outputDirectory } = await prompt.prompt([
{
type: prompt.Input,
name: "outputDirectory",
message: "Output directory to set as $out",
default: ".",
},
{ {
type: prompt.Input, type: prompt.Input,
name: "filename", name: "filename",
@ -154,7 +162,11 @@ async function actionHandler(
const commands = constructedCommands.map((c) => c.join(" ")).join("\n"); const commands = constructedCommands.map((c) => c.join(" ")).join("\n");
await Deno.writeTextFile( await Deno.writeTextFile(
filename ?? defaultFilename, filename ?? defaultFilename,
`#!/usr/bin/env zsh\n\nsource "$HOME/.aliases.zsh"\n\n${commands}`, `#!/usr/bin/env zsh
source "$HOME/.aliases.zsh"
out="${outputDirectory}"
${commands}`,
); );
} else { } else {
console.log("\n## Output"); console.log("\n## Output");