1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

各種コマンドのカラー表示出力化(alias 利用)

Last updated at Posted at 2018-02-04

こんにちは
各種コマンドのカラー表示出力化のために alias を作ってみました(参考記事:linux(CentOS)のコマンドに色付け)。

$ alias
alias grepc='grep --color=always'
alias diffc='colordiff'
alias lessc='less -R'
alias lvc='lv -c'
alias jqc='jq -C'
alias lsc='CLICOLOR_FORCE=1 ls -G'
alias source-highlightc='source-highlight -f esc'
$ source-highlightc -i sample.py | lessc

unbuffer コマンド

なおデフォルトでカラー表示出力するコマンドは、出力をパイブラインへ渡した場合は通常はカラーは抑止する作りになっていますが、unbuffer コマンドを使えばエスケープシーケンスは抑止されません(参考記事:less にパイプしても色が消えないようにする方法)。

$ brew install expect
$ which unbuffer
/usr/local/bin/unbuffer
$ unbuffer command_color_output | lessc
1
3
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
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?