terminalxtermcolorizetext-coloringansi-colors

Invoke grc terminal colorizer on ALL commands implicitly


I love the grc colorizer for the terminal. However I have to explicitly prefix anything I want colorized with:

grc --config=conf.mine

Is there any way to have it automatically applied to everything you input on the command line (so that potentially I don't even need to know what grc is)? Perhaps using shell hooks, if a better alternative doesn't exist?


Solution

  • The grc.bashrc and grc.zsh files provided with grc since v1.9 does this in a (non-complete) way by adding aliases for common commands:

    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