openEditor static method

Cmd openEditor(
  1. String filePath, {
  2. required Msg onComplete(
    1. ExecResult result
    ),
})

A command that opens an editor for the given file.

Uses the EDITOR environment variable, falling back to vi on Unix or notepad on Windows.

Cmd.openEditor(
  '/path/to/file.txt',
  onComplete: (result) => EditorClosedMsg(result.success),
)

Implementation

static Cmd openEditor(
  String filePath, {
  required Msg Function(ExecResult result) onComplete,
}) {
  final editor =
      io.Platform.environment['EDITOR'] ??
      io.Platform.environment['VISUAL'] ??
      (io.Platform.isWindows ? 'notepad' : 'vi');

  return exec(editor, [filePath], onComplete: onComplete);
}