From 07738ea86330b7b77127fc6f18474b3da2c6ecec Mon Sep 17 00:00:00 2001 From: Oleg Kandaurov Date: Fri, 12 Apr 2013 18:19:42 +0400 Subject: [PATCH] Add colorize plugin --- plugins/colorize/colorize.plugin.zsh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 plugins/colorize/colorize.plugin.zsh diff --git a/plugins/colorize/colorize.plugin.zsh b/plugins/colorize/colorize.plugin.zsh new file mode 100644 index 00000000..0696607d --- /dev/null +++ b/plugins/colorize/colorize.plugin.zsh @@ -0,0 +1,28 @@ +# Plugin for highligthing file content +# Plugin highlights file content based on the filename extension. +# If no highlighting method supported for given extension then it tries +# guess it by looking for file content. + +alias colorize='colorize_via_pygmentize' + +colorize_via_pygmentize() { + if [ ! -x $(which pygmentize) ]; then + echo package \'pygmentize\' is not installed! + exit -1 + fi + + if [ $# -eq 0 ]; then + pygmentize -g $@ + fi + + for FNAME in $@ + do + filename=$(basename "$FNAME") + lexer=`pygmentize -N \"$filename\"` + if [ "Z$lexer" != "Ztext" ]; then + pygmentize -l $lexer "$FNAME" + else + pygmentize -g "$FNAME" + fi + done +} \ No newline at end of file