我喜欢终端的grc着色器。但是,我必须显式地添加要着色的内容的前缀:
grc --config=conf.mine
有什么方法可以将其自动应用于您在命令行上输入的所有内容(这样一来,我什至不需要知道grc是什么)?如果不存在更好的替代方法,也许使用 shell 钩子(Hook)?
最佳答案
自v1.9以来,grc随附的grc.bashrc和grc.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