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