LoginSignup
10
2

More than 5 years have passed since last update.

jQの結果をlessで見るときに色付きで見る方法

Posted at
echo '{"foo":[{"bar":1}]}' | jq '.' -C | less -R

みたいな感じでやる。

$ man jq
--color-output / -C and --monochrome-output / -M:
    By default, jq outputs colored JSON if writing to a terminal. You can force it to produce color even if writing to a pipe or a file
    using -C, and disable color with -M.

的な感じで色付きでパイプさせて

$ man less
-R or --RAW-CONTROL-CHARS
    Like -r, but only ANSI "color" escape sequences are output in "raw" form.  Unlike -r, the screen appearance is  maintained  cor-
    rectly in most cases.  ANSI "color" escape sequences are sequences of the form:

        ESC [ ... m

    where the "..." is zero or more color specification characters For the purpose of keeping track of screen appearance, ANSI color
    escape sequences are assumed to not move the cursor.  You can make less think that characters other than "m" can end ANSI  color
    escape  sequences  by  setting  the environment variable LESSANSIENDCHARS to the list of characters which can end a color escape
    sequence.  And you can make less think that characters other than the standard ones may appear between the ESC and the m by set-
    ting the environment variable LESSANSIMIDCHARS to the list of characters which can appear.

的な感じで色付きで受け取る

10
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
2