Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: Warning: Input is not from a terminal

Tags:

bash

vim

I wrote simple jsonview script to view json files:

#!/bin/bash
tmp_file=/tmp/jsonview.json
cat "${@}" | python -m json.tool > $tmp_file
[[ -f $tmp_file ]]  &&  vim $tmp_file

I am not using less because I need syntax highlighting. That useless use of cat cat ${@} | ... is so that script can be used as a filter:

jsonview t.json

and:

cat t.json | jsonview

If jsonview used as in second, pipe case - despite the fact that vim is invoked not on pipe but on concrete file, I am getting that warning in subject. I can view json file, but after exit, it messes up terminal. Why is this warning? Why vim thinks that it reads from a pipe?

like image 500
Leonid Volnitsky Avatar asked Mar 13 '16 17:03

Leonid Volnitsky


1 Answers

Vim doesn't like it when standard input is redirected unless you invoke it as vim -. In that case it knows stdin is redirected and handles it. As a side benefit it also lets you get rid of the temp file.

#!/bin/bash
cat "$@" | python -m json.tool | vim +'set syntax=javascript' -R -

Always quote "$@" to ensure file names with whitespace won't mess your script up.

-R gets rid of the prompt to save the buffer when exiting Vim.

like image 73
John Kugelman Avatar answered Sep 22 '22 15:09

John Kugelman