메뉴 닫기

Colout – Color Up Arbitrary Command Output

검은 Shell 화면에 컬러풀한 색깔을 입혀서 로그파일 및 소스코드를 볼때 확~ 눈에 띄게 보는 방법입니다.
설치가 간단하고 패턴을 조합해  텍스트를 다양하게 꾸밀수 있습니다.
여기서는 간단한 몇가지 예시만을 알려드립니다.

 

테스트 환경
 OS : Ubuntu 14.04 LTS

colout – 터미널 텍스트에 색깔을 입히는 명렁어
install
# apt-get install python-setuptools
# easy_install colout

사용방법은 아래와 같습니다.
example
<text stream> | colout <pattern to color> [color [style]]

Example1)
# tail -n 10 /var/log/boot.log |colout OK
OK 단어가 포함된것만 붉은색(기본)으로 표시
colou1

Example2)
# tail -n 10 /var/log/boot.log |colout OK yellow bold
OK 단어가 포함된것만 노란색으로 표시
colou2

Example3)
#  tail -n 10 /var/log/boot.log |colout  “^.*OK.*$” red bold
OK 단어가 포함된 줄 모두 노란색으로 표시
colou3

Example4)
Color maps
# tail /var/log/boot.log |colout “^.*$” rainbow
무지개 (빨주노초파남보) 패턴으로 표시
colou4

Example5)
# tail /var/log/boot.log | colout -c “^.*$” blue,yellow,white normal
-c 옵션을 사용해서 라인마다 원하는 색상 지정 (파란색, 노란색, 흰색)
colou5

Example6)
# tail /var/log/boot.log | colout “^.*$” random
각 라인마다 랜덤하게 색상표시
colou6

Example7)
# tail -n 20 /etc/openstack-dashboard/local_settings.py | grep -v “^\s*$” | colout -s Python monokai
오픈스택내  Python Source Code 강조
colout -s [PATTERN] [COLOR]
colou7

이외에도 아래와 같은 옵션들이 존재하며….좀더 다양한 예제는 아래 남겨둔 원작자 링크를 참조하세요.
# colout  –help
usage: colout.py [-h] [-g] [-c] [-l SCALE] [-a] [-t] [-T DIR] [-P DIR] [-r]
                 [–debug] [-s]
                 REGEX [COLOR] [STYLE]

A regular expression based formatter that color up an arbitrary text stream.

positional arguments:
  REGEX                 A regular expression
  COLOR                 A number in [0…255], a color name, a colormap name,
                        a palette or a comma-separated list of those values.
  STYLE                 One of the available styles or a comma-separated list
                        of styles.

optional arguments:
  -h, –help            show this help message and exit
  -g, –groups          For color maps (random, rainbow), iterate over
                        matching groups in the pattern instead of over
                        patterns
  -c, –colormap        Use the given colors as a colormap (cycle the colors
                        at each match)
  -l SCALE, –scale SCALE
                        When using the ‘scale’ colormap, parse matches as
                        decimal numbers (taking your locale into account) and
                        apply the rainbow colormap linearly between the given
                        SCALE=min,max
  -a, –all             Color the whole input at once instead of line per line
                        (really useful for coloring a source code file with
                        strings on multiple lines).
  -t, –theme           Interpret REGEX as a theme.
  -T DIR, –themes-dir DIR
                        Search for additional themes (colout_*.py files) in
                        this directory
  -P DIR, –palettes-dir DIR
                        Search for additional palettes (*.gpl files) in this
                        directory
  -r, –resources       Print the names of all available colors, styles,
                        themes and palettes.
  –debug               Debug mode: print what’s going on internally, useful
                        if you want to check what features are available.
  -s, –source          Interpret REGEX as a source code readable by the
                        Pygments library. If the first letter of PATTERN is
                        upper case, use the 256 colors mode, if it is lower
                        case, use the 8 colors mode. Interpret COLOR as a
                        Pygments style.
참조  http://nojhan.github.io/colout/
        https://github.com/nojhan/colout

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x