fortune可以随机在终端输出一段格言谚语,类似这样

1
2
3
4
5
6
7
8
9
10
11
12
13
  $ fortune
Congratulations! You have purchased an extremely fine device that would
give you thousands of years of trouble-free service, except that you
undoubtably will destroy it via some typical bonehead consumer maneuver.
Which is why we ask you to PLEASE FOR GOD'S SAKE READ THIS OWNER'S MANUAL
CAREFULLY BEFORE YOU UNPACK THE DEVICE. YOU ALREADY UNPACKED IT, DIDN'T
YOU? YOU UNPACKED IT AND PLUGGED IT IN AND TURNED IT ON AND FIDDLED WITH
THE KNOBS, AND NOW YOUR CHILD, THE SAME CHILD WHO ONCE SHOVED A POLISH
SAUSAGE INTO YOUR VIDEOCASSETTE RECORDER AND SET IT ON "FAST FORWARD", THIS
CHILD ALSO IS FIDDLING WITH THE KNOBS, RIGHT? AND YOU'RE JUST NOW STARTING
TO READ THE INSTRUCTIONS, RIGHT??? WE MIGHT AS WELL JUST BREAK THESE
DEVICES RIGHT AT THE FACTORY BEFORE WE SHIP THEM OUT, YOU KNOW THAT?
-- Dave Barry, "Read This First!"

安装

1
brew install fortune

配置中文

fortune自带了一些英文词库,当然我们更希望有一些中文的诗词谚语等,感谢github上ruanyf大哥的分享

1
2
3
4
5
6
7
8
# Mac
$ git clone git@github.com:ruanyf/fortunes.git
$ strfile fortunes/data/fortunes
$ strfile fortunes/data/chinese
$ strfile fortunes/data/tang300
$ strfile fortunes/data/song100
$ strfile fortunes/data/diet

这里要注意github上原作者将文件拷贝到了/usr/share目录,但是实测发现这么拷贝会提示权限不足,强行授权拷贝后也无效,应该是文件目录有变动,这里先查看下自己安装的fortune的词典位置

1
2
3
4
5
6
7
8
9
10
fortune -f
100.00% /opt/homebrew/Cellar/fortune/9708/share/games/fortunes
7.65% computers
1.01% riddles
4.36% men-women
1.92% literature
1.13% love
0.22% magic
0.79% linuxcookie
1.56% drugs

将中文词典拷贝到fortune词典目录

1
mv fortunes/data/* /opt/homebrew/Cellar/fortune/9708/share/games/fortunes

验证一下,可以看到song100,Chinese等词典了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
fortune -f
100.00% /opt/homebrew/Cellar/fortune/9708/share/games/fortunes
0.25% song100
2.52% computers
0.33% riddles
1.44% men-women
0.77% tang300
0.63% literature
0.37% love
0.07% magic
0.26% linuxcookie
0.51% drugs
0.13% pets
1.14% art
0.50% law
0.13% goedel
0.50% education
0.40% ethnic
1.54% science
0.02% ascii-art
0.24% diet
1.59% miscellaneous
0.36% sports
1.35% zippy
1.71% politics
0.56% startrek
0.99% wisdom
0.13% news
1.56% work
0.18% medicine
3.04% people
0.49% food
0.48% humorists
1.23% platitudes
53.41% chinese

配置频率

可以根据自己喜好调整出现频率

1
2
3
4
5
6
7
$ fortune -e chinese fortunes
# is equivalent to
$ fortune 50% chinese 50% fortunes

$ fortune -e chinese fortunes tang300 song100
# is equivalent to
$ fortune 25% chinese 25% fortunes 25% tang300 25% song100

配合cowsay使用

1
2
3
4
5
6
7
8
9
10
11
12
$ fortune |cowsay
_________________________________________
/ 永生,就是世世代代都有人虔 \
| 诚地 |
| |
\     - 美洲 /
-----------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||

当然一般也没人手动去打这个命令,所以设置成终端打开自动执行这个命令,zsh可以直接在.zshrc中添加一行fortune |cowsay就好了。

参考:
ruanyf/fortunes: A collection of fortune database files for Chinese users. (github.com)