colorize.plugin.zsh 730 B

12345678910111213141516171819202122232425262728
  1. # Plugin for highligthing file content
  2. # Plugin highlights file content based on the filename extension.
  3. # If no highlighting method supported for given extension then it tries
  4. # guess it by looking for file content.
  5. alias colorize='colorize_via_pygmentize'
  6. colorize_via_pygmentize() {
  7. if [ ! -x $(which pygmentize) ]; then
  8. echo package \'pygmentize\' is not installed!
  9. exit -1
  10. fi
  11. if [ $# -eq 0 ]; then
  12. pygmentize -g $@
  13. fi
  14. for FNAME in $@
  15. do
  16. filename=$(basename "$FNAME")
  17. lexer=`pygmentize -N \"$filename\"`
  18. if [ "Z$lexer" != "Ztext" ]; then
  19. pygmentize -l $lexer "$FNAME"
  20. else
  21. pygmentize -g "$FNAME"
  22. fi
  23. done
  24. }