这里通过构建fortune、cowsay、lolcat组合拳对Mac终端进行美化

fortune
该命令每次执行时,会随机输出一句人生格言
1 2 3 4 5
| brew install fortune
fortune -v
|

只不过fortune默认的格言库是英文的。这里我们期望能够输出中国的古诗词之类的
1 2 3 4 5 6
| git clone https://github.com/ruanyf/fortunes.git
cd ./fortunes/data strfile fortunes && strfile chinese && strfile tang300 && strfile song100
|

1 2 3 4 5
| brew list fortune | grep -E "games/fortunes/" | head -n 1
sudo mv fortunes/data/* /usr/local/Cellar/fortune/9708/share/games/fortunes/
|

1 2
| fortune 25% fortunes 25% chinese 25% tang300 25% song100
|

cowsay
该命令接受一个文本,然后通过动物说话的图形进行展示
用法如下
1 2 3 4 5 6 7
| cowsay "Good"
cowsay -l
cowsay -f cheese "Good"
|

lolcat
该命令可以对命令行对输出产生彩虹的颜色效果
效果如下

组合拳
现在我们来编写一个Shell脚本。实现启动终端时,会随机选择一种动物随机输出一条彩虹效果的格言。其中,cowsay命令的配置文件路径可通过cowsay -l命令获取

脚本文件cowSayFortuneBylolcat.sh如下所示
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| #!/usr/local/bin/zsh
cowsay_config_path=/usr/local/Cellar/cowsay/3.04_1/share/cows
animal_counts=`ls -1 ${cowsay_config_path} | grep "\.cow$" | wc -l`
rand_num=`jot -r 1 1 ${animal_counts}`
animal=`ls -1 ${cowsay_config_path} | grep "\.cow$" | sort | sed -n "${rand_num}p"`
fortune 10% fortunes 30% chinese 30% tang300 30% song100 | cowsay -f ${animal} | lolcat
|
现在对该脚本执行权限
1 2
| chmod u+x cowSayFortuneBylolcat.sh
|

这里我们使用的Shell为zsh。故在用户目录下的.zshrc文件中添加执行该脚本的命令
1 2 3 4
| ...
~/CustomShellScript/cowSayFortuneBylolcat.sh ...
|
