ohmyzsh/plugins/colorize/colorize.plugin.zsh
ivan 2b2cef6515 add ccat support
Signed-off-by: ivan <qw7692336@gmail.com>
2016-02-22 15:12:32 +08:00

34 lines
853 B
Bash

# Plugin for highlighting 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() {
# https://github.com/jingweno/ccat
if [ -x "$(which ccat)" ]; then
ccat $@
return 0
fi
if [ ! -x "$(which pygmentize)" ]; then
echo "package \'pygmentize\' is not installed!"
return -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
}