Syntax highlighting/colorizing cat

前端 未结 18 1887
不思量自难忘°
不思量自难忘° 2020-12-02 03:39

Is there a method to colorize the output of cat, the way grep does.

For grep, in most consoles it displays a colored output hi

18条回答
  •  离开以前
    2020-12-02 04:10

    Options:

    pygmentize is good. I have an alias:

    alias c='pygmentize -g'
    

    but highlight is another widely available alternative is

    alias cats='highlight -O ansi --force'
    

    Installation:

    You may have to install pygments using one of these:

    sudo apt install python-pygments
    sudo pip install pygments
    sudo easy_install Pygments #for Mac user
    

    and for highlight package which is easily available on all distributions

    sudo apt install highlight
    sudo yum install highlight
    
    • Bitbucket repo: https://bitbucket.org/birkenfeld/pygments-main
    • GitHub mirror: https://github.com/sglyon/pygments

    In Action:

    I'm attaching shots for both down below for a good comparison in highlightings

    Here is pygmentize in action: Pygmentize highlighting on python file

    and this is highlight: Highlight highlighting on python file

提交回复
热议问题