Advertisement
v1ral_ITS

colorize terminal output

Apr 18th, 2019
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.66 KB | None | 0 0
  1. # easier alias to use the plugin
  2. alias ccat='colorize_via_pygmentize'
  3.  
  4. colorize_via_pygmentize() {
  5.     if ! (( $+commands[pygmentize] )); then
  6.         echo "package 'Pygments' is not installed!"
  7.         return 1
  8.     fi
  9.  
  10.     # pygmentize stdin if no arguments passed
  11.     if [ $# -eq 0 ]; then
  12.         pygmentize -g
  13.         return $?
  14.     fi
  15.  
  16.     # guess lexer from file extension, or
  17.     # guess it from file contents if unsuccessful
  18.     local FNAME lexer
  19.     for FNAME in $@
  20.     do
  21.         lexer=$(pygmentize -N "$FNAME")
  22.         if [[ $lexer != text ]]; then
  23.             pygmentize -l "$lexer" "$FNAME"
  24.         else
  25.             pygmentize -g "$FNAME"
  26.         fi
  27.     done
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement