Saturday, June 19, 2010

Getting the exit code from make in Vim

Just answered the question on SO and I think the final trick is worth documenting here. The problem is how to get after :make exit code of the make itself. As it is wrapped by VIM, it gets lost in the pipe: :echo v:shell_error always shows 0 (:h v:shell_error).

The bash-specific trick is:

:set shellpipe=2>&1\ \|\ tee\ %s;exit\ \${PIPESTATUS[0]}

The magic is in the ;exit ${PIPESTATUS[0]}.

man bash (search for PIPESTATUS) and :h 'shellpipe' (check the %s) for more info.


Anonymous said...

The link above should be to this question.

Ihar Filipau said...

Thanks Anon, fixed.

gauri said...

Don't have an account on a SO, so I post it here, maybe someone find it helpful:

if you're using zsh instead of bash (see :set shell), you can use this method, only use

exit\ \${pipestatus[1]}

at the end