Skip to content

More screen magic, now with povray

by Stephen Mann on December 6th, 2009

The goal: hit F5 to rerender scene.

The line in .vimrc:

nmap <F5> :update<CR>:call system("screen -X stuff 'clear; povray ".@%."; open $(basename ".@%." .pov).png; open ".@%."; \n'")<CR>

And how it works:

  • nmap <F5> to set shortcut key
  • :update<CR> to save the current file
  • :call system("screen -X stuff '...'")<CR> This combination makes a call to the system (a terminal). That call runs the screen -X stuff '...' command, which inserts '...' into the current screen session.
  • Looking at the "..." piece by piece:
  • clear clears the terminal
  • povray ".@%." feeds the current file into the povray command-line utility. % is the current file. @% accesses the current file. The "‘s escape from the string, and the . is concatenation.
  • open $(basename ".@%." .pov).png Opens (refreshes the view of) the new .png. basename is a function that strips a filename’s extension. $() evaluations an expression in bash.
  • open ".@%." Opens the file back up in vim — serves to return focus to the file I’m editing.
  • \n enter, makes the command go

The result of all this trickery is ease. I hit F5, and all my windows auto-update — terminal, image viewer, and vim. The only thing left to do is locate some artistic talent.

From → tech

No comments yet

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS