colorize.plugin.zsh 673 B

12345678910111213141516171819202122232425262728
  1. # easier alias to use the plugin
  2. alias ccat='colorize_via_pygmentize'
  3. colorize_via_pygmentize() {
  4. if ! (( $+commands[pygmentize] )); then
  5. echo "package 'Pygments' is not installed!"
  6. return 1
  7. fi
  8. # pygmentize stdin if no arguments passed
  9. if [ $# -eq 0 ]; then
  10. pygmentize -g
  11. return $?
  12. fi
  13. # guess lexer from file extension, or
  14. # guess it from file contents if unsuccessful
  15. local FNAME lexer
  16. for FNAME in $@
  17. do
  18. lexer=$(pygmentize -N "$FNAME")
  19. if [[ $lexer != text ]]; then
  20. pygmentize -l "$lexer" "$FNAME"
  21. else
  22. pygmentize -g "$FNAME"
  23. fi
  24. done
  25. }