Skip to content
Advertisement

How can I launch vim from my program and capture the written output, like Git commit

Like the title suggests, I’d like to basically emulate the behavior of git commit where it launches a text editor and when you save the output, it captures the output.

Anyone have an idea of how to do this? I tried to look through the git source to copy the solution but didn’t really succeed in finding the relevant portion.

If it matters my scripts are in ruby.

Thanks a lot,

Cameron

Advertisement

Answer

git creates a temporary file and executes:

vim .git/COMMIT_EDITMSG #It actually looks at EDITOR in your environment, if it is set.

And after vim closes, the file is read from, and it goes on its merry way.

Advertisement