Figured out that there are some difficulties on printing source code in Mac OS, especially in lightweight text editors like Sublime Text 2 which doesn’t support printing right now and TextMate which in my opinion produces not cozy and beautiful result.

There is nice program called enscript and it is probably can do a lot of good things, but in our case can produce a PostScript file with printed code. In Mac OS X it can be installed using brew, brew install enscript.

So, here is a good example using encsript :

enscript -1rG --line-numbers -p - \
  --highlight=javascript --color=1 -c untitled.js > ~/ \
  && open ~/

Everything is pretty clear, but

  • 1 is for printing one page per sheet
  • -r is for album mode, remove it to print for usual book mode
  • -p - for producing ps output, after that it piped to file ~/
  • –color=0 for black/white mode
  • –color=1 for colored mode
  • -c is for cutting lines, if they are bigger than the actual width of a sheet. There is also –word-wrap option

Another example with automatic conversion to pdf using ps2pdf :

enscript -2rG --line-numbers -p - \
  --word-wrap --highlight=javascript --color=0 untitled.js | \
  pstopdf -i -o ~/out.pdf && open ~/out.pdf

In conclusion, a good idea for you - you can open your start-up project on printing code files(ruby, perl, js, c#, etcetera) with right click in Mac OS X using Automation services. Simple problem, simple solution.