Spawning vim from a node git hook

Posted by Lawrence Jones on Stack Overflow See other posts from Stack Overflow or by Lawrence Jones
Published on 2014-06-01T21:21:21Z Indexed on 2014/06/01 21:25 UTC
Read the original article Hit count: 199

Filed under:
|
|
|
|

I've got a project purely in coffeescript, with git hooks for deployment also written in cs. I don't really want to break away from the language just to use bash for a quick commit message formatter, but I've got a problem spawning vim from the commit-msg hook.

I've seen here that when piping to vim, the stdio is not necessarily set correctly to the tty streams. I get how that could cause a problem, but I don't exactly know how to get vim to load correctly using nodes spawn command. At the moment I have...

vim = (require 'child_process').spawn('vim', [file], stdio: 'inherit')
vim.on 'exit', (err) ->
  console.log "Exited! [#{err}]"
  cb?()

...which works fine to spawn a vim process that can r/w from the parents stdio, but when I use this in the hook things go wrong. Vim states that the stdio is not from terminal, and then once opened typing causes escape characters to pop up all over the place. Backspace for example, will produce ^?.

Any help would be appreciated!

© Stack Overflow or respective owner

Related posts about node.js

Related posts about git