隐式地在ALL命令上调用grc终端颜色

时间:2012-08-10 22:47:50

标签: terminal xterm colorize text-coloring ansi-colors

我喜欢终端的grc colorizer。但是我必须明确地为我想要着色的任何东西添加前缀:

grc --config=conf.mine

有没有办法让它自动应用到您在命令行输入的所有内容(这样我甚至不需要知道grc是什么)?也许使用shell钩子,如果不存在更好的替代方案?

2 个答案:

答案 0 :(得分:4)

自v1.9以来随grc提供的grc.bashrcgrc.zsh文件通过为常用命令添加别名以(非完整)方式执行此操作:

<强> grc.bashrc

GRC=`which grc`
if [ "$TERM" != dumb ] && [ -n "$GRC" ]
then
    alias colourify="$GRC -es --colour=auto"
    alias configure='colourify ./configure'
    alias diff='colourify diff'
    alias make='colourify make'
    alias gcc='colourify gcc'
    alias g++='colourify g++'
    alias as='colourify as'
    alias gas='colourify gas'
    alias ld='colourify ld'
    alias netstat='colourify netstat'
    alias ping='colourify ping'
    alias traceroute='colourify /usr/sbin/traceroute'
    alias head='colourify head'
    alias tail='colourify tail'
    alias dig='colourify dig'
    alias mount='colourify mount'
    alias ps='colourify ps'
    alias mtr='colourify mtr'
    alias df='colourify df'
fi

<强> grc.zsh

if [[ "$TERM" != dumb ]] && (( $+commands[grc] )) ; then
  # Prevent grc aliases from overriding zsh completions.
  setopt COMPLETE_ALIASES

  # Supported commands
  cmds=(
    cc \
    configure \
    cvs \
    df \
    diff \
    dig \
    gcc \
    gmake \
    ifconfig \
    last \
    ldap \
    ls \
    make \
    mount \
    mtr \
    netstat \
    ping \
    ping6 \
    ps \
    traceroute \
    traceroute6 \
    wdiff \
  );

  # Set alias for available commands.
  for cmd in $cmds ; do
    if (( $+commands[$cmd] )) ; then
      alias $cmd="grc --colour=auto $cmd"
    fi
  done

  # Clean up variables
  unset cmds cmd
fi

答案 1 :(得分:0)

我尝试过,它对我有用:

alias ls="ls -FHG"