2014-05-08 11:19:37 -07:00
|
|
|
# Plugin for highlighting file content
|
2013-04-12 07:19:42 -07:00
|
|
|
# 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.
|
|
|
|
|
2018-01-22 20:18:03 -07:00
|
|
|
#easier alias to use plugin
|
|
|
|
alias ccat='colorize_via_pygmentize'
|
2013-04-12 07:19:42 -07:00
|
|
|
|
|
|
|
colorize_via_pygmentize() {
|
2013-07-09 04:51:52 -07:00
|
|
|
if [ ! -x "$(which pygmentize)" ]; then
|
2018-01-22 20:18:03 -07:00
|
|
|
echo "package \'Pygments\' is not installed!"
|
2013-07-09 04:51:52 -07:00
|
|
|
return -1
|
2013-04-12 07:19:42 -07:00
|
|
|
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
|
2014-05-08 11:19:37 -07:00
|
|
|
}
|