0
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-09-19 04:01:21 +02:00
ohmyzsh/plugins/colorize/colorize.plugin.zsh
GIL B. Chan 67e0ef7aa6 edit colorize plugin: add -f terminal option
The option (`pygmentize -f terminal <...>`) lets pygments use terminal color
scheme. Otherwise, it would use its default colors, which might be
unbalanced with that of terminal (e.g. not harmonious with background color of terminal).
2019-04-07 18:57:17 +09:00

28 lines
709 B
Bash

# 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 -f terminal -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 -f terminal -l "$lexer" "$FNAME"
else
pygmentize -f terminal -g "$FNAME"
fi
done
}