Color Linux command output

后端 未结 10 1335
天命终不由人
天命终不由人 2020-12-09 19:03

For example, I\'d like to color the output of the locate command so it\'s easily distinguished from the other terminal text.

It should work something li

10条回答
  •  有刺的猬
    2020-12-09 19:46

    There is a far better way to achieve customizable coloring:

    colorit

    You can use it as shown in other answers via some_command | colorit but it is nicely configurable over the .coloritrc. In mine I have stuff like

    dnl  Define some useful color variables
    define(`red', `1')
    define(`green', `2')
    define(`magenta', `5')
    dnl
    dnl  Mark macro arguments: regexp foreground-color [background-color]
    dnl
    define(`mark', ``mark "$1"'' `ifelse(`$#', `3', ``"\033[3$2;4$3m"'',
    ``"\033[3$2m"'')' `"\033[m"')
    dnl
    divert
    mark(`warning', magenta)
    mark(`Warning', magenta)
    mark(`Traceback', magenta)
    mark(`Error', red)
    mark(`FAIL', red)
    mark(`ERROR', red)
    mark(`XFAIL', green)
    mark(`ok', green)
    mark(`OK', green)
    mark(`PASS', green)
    

    and use it all the time for coloring compiler output and similar stuff. See my .coloritrc for more.

提交回复
热议问题