public static void editFile(Path filePath) throws IOException, InterruptedException {
    if (System.console() == null) {
      throw new IllegalStateException("Script must be run from a terminal to support opening a file in an editor");
    }

    String editor = System.getenv("EDITOR");
    List<String> command = new ArrayList<>();
    if (editor == null) {
      command.add("vim");
    } else {
      // If the EDITOR variable contains extra arguments, we have to split the string into tokens.
      StringTokenizer st = new StringTokenizer(editor);
      while (st.hasMoreTokens()) {
        command.add(st.nextToken());
      }
    }
    command.add(filePath.toAbsolutePath().toString());

    Process process = new ProcessBuilder(command).redirectInput(ProcessBuilder.Redirect.INHERIT)
        .redirectOutput(ProcessBuilder.Redirect.INHERIT)
        .start();
    process.waitFor();
  }
Open a file for editing in a terminal text editor. Wait for the editor process to finish before returning.
This should only be called from scripts that are run in a terminal as it requires user input.
If the {@code EDITOR} environment variable is set, that editor is used, otherwise it defaults to vim.
@param filePath the file to edit.
@throws IOException
@throws InterruptedException
ambry-tools/src/main/java/com/github/ambry/tools/util/ToolUtils.java