Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

CLI: implement something like git commit (open a text editor and get value)

CLI: implement something like git commit (open a text editor and get value)

Problem

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.

Thanks.

Problem courtesy of: user2433617

Solution

Typically, you do four things:

  1. Create a temporary file
  2. Fork an external process which execs the program specified in the environment variable $EDITOR, giving the name of the temporary file as an argument.
  3. Wait for the process to return.
  4. Open and read from the temporary file to see what the user wrote.
Solution courtesy of: chepner

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

CLI: implement something like git commit (open a text editor and get value)

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×