开发者

passing contents to EDITOR and getting the results after quit (e.g. git/svn commit)

开发者 https://www.devze.com 2022-12-21 01:50 出处:网络
I would like to开发者_运维问答 write a command line tool that passes some formatted text to whatever EDITOR the user has set in the environment and then reading the contents back.

I would like to开发者_运维问答 write a command line tool that passes some formatted text to whatever EDITOR the user has set in the environment and then reading the contents back.

How do tools like svn commit and git commit handle this behavior? Is there a standard pattern for doing this?


hmm, maybe...

  • Create a temporary file with the content you want.
  • Open the file in the $EDITOR.
  • Wait until the editor was closed
  • Check the modification date of the file
    • unchanged: The user has probably aborted the editing process
    • changed: use the content of the modified file
  • Delete the temporary file

If you have a question to one of these tasks, feel free to ask :)


#!/bin/bash
cat | $EDITOR - &
wait $!
echo "now editor has exited"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号