Edit a string with the users preferred text editor using $VISUAL or $ENVIRONMENT
79
A module that edits text by running a temporary file through a caller-specified editor command, returning the edited contents and the command's exit status.
initialText of "draft" and a command { bin: "node", args: ["-e", "const fs=require('fs'); const p=process.argv[2]; const s=fs.readFileSync(p,'utf8'); fs.writeFileSync(p, s.toUpperCase());"] }, the function resolves with text equal to "DRAFT" and exitCode equal to 0. @test{ bin: "node", args: ["-e", "const fs=require('fs'); const p=process.argv[2]; fs.writeFileSync(p, 'kept'); process.exit(13);"] }, the function resolves with text equal to "kept" and exitCode equal to 13. @testinitialText of "seed" and a command { bin: "bash", args: ["-c", "echo added >> \"$1\"", "--"] }, the function passes the temporary file path as the final argument so the script can write to it, resulting in text that ends with a newline followed by "added" and commandUsed whose last element is that temp file path. @test@generates
export interface ScriptedEditorOptions {
initialText?: string;
command: { bin: string; args: string[] };
}
export interface ScriptedEditorResult {
text: string;
exitCode: number;
commandUsed: string[];
}
/**
* Writes the initial text to a temporary file, runs the provided command against that file, and returns the edited contents plus the exit status.
*/
export function runScriptedEdit(options: ScriptedEditorOptions): Promise<ScriptedEditorResult>;Used to create a temporary file, launch the chosen editor command, and read back the edited contents.
@satisfied-by
Install with Tessl CLI
npx tessl i tessl/npm-external-editordocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10