7

我喜欢终端的 grc 着色器。但是,我必须明确地为我想要着色的任何内容添加前缀:

grc --config=conf.mine

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

4

2 回答 2

6

自 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
于 2015-10-27T09:01:08.843 回答
-3

我试过这个,它对我有用:

alias ls="ls -FHG"
于 2019-07-23T08:21:54.933 回答