Syntax highlighting/colorizing cat

前端 未结 18 1926
不思量自难忘°
不思量自难忘° 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:24

    There is a colorized version of cat - ccat. Get it from https://github.com/jingweno/ccat/.

    Installation on Linux/Windows/macOS

    It is a single standalone executable so to install it you can unpack the binary version for your OS from https://github.com/jingweno/ccat/releases and copy the ccat binary for example to /usr/local/bin.

    If you want to avoid binaries, or if there is no binary for your platform (e.g. raspberry pi, etc), then you can alternately compile from source given that you have a working go development environment (apt install golang on debian-based linuxes or brew install golang on mac):

    go get -u github.com/jingweno/ccat
    

    The ccat binary will be created under your $GOPATH/bin.

    Installing on Mac via homebrew

    brew install ccat
    

    Alias to cat

    To replace regular cat with ccat add in ~/.bashrc (~/.zshrc, etc..):

    alias cat="ccat $*"
    alias cat0="/bin/cat $*" # for cases when you need plain `cat`
    

    ccat is implemented in Go, so it is a native binary which runs much faster than Python-based solutions, such as pygments, the module behind pygmentize; I didn't see any noticeable speed difference between cat and ccat.

提交回复
热议问题