CLI: implement something like git commit (open a text editor and get value)
I am making a command line app. I want to allow the user, when they are adding values for things in the terminal, to be able to add the value with their text Editor. How does git achieve this?
I want to open their default editor, allow them to enter text, and when they save get the value and use that value for my app.
Typically, you do four things:
- Create a temporary file
- Fork an external process which execs the program specified in the environment variable
$EDITOR, giving the name of the temporary file as an argument.
- Wait for the process to return.
- Open and read from the temporary file to see what the user wrote.