colorize.plugin.zsh 759 B

1234567891011121314151617181920212223242526272829
  1. # Plugin for highlighting 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. #easier alias to use plugin
  6. alias ccat='colorize_via_pygmentize'
  7. colorize_via_pygmentize() {
  8. if [ ! -x "$(which pygmentize)" ]; then
  9. echo "package \'Pygments\' is not installed!"
  10. return -1
  11. fi
  12. if [ $# -eq 0 ]; then
  13. pygmentize -g $@
  14. fi
  15. for FNAME in $@
  16. do
  17. filename=$(basename "$FNAME")
  18. lexer=`pygmentize -N \"$filename\"`
  19. if [ "Z$lexer" != "Ztext" ]; then
  20. pygmentize -l $lexer "$FNAME"
  21. else
  22. pygmentize -g "$FNAME"
  23. fi
  24. done
  25. }