创建Fortunes文件

如何创建fortunes文件并将其添加到shell上的fortune *命令?

*财富 – “控制台命令打印随机,希望有趣,格言。”

这在fortune(6)和(特别是) strfile(1)的联机帮助页中有解释。

基本上,您创建一个文本文件,其中包含由“包含单个%符号”的行分隔的“幸运cookies”,而不包含任何其他内容。 每个幸运cookies可以是1行或更多行(包括空行)。 来自其中一个默认幸运cookie文件的随机示例:

 A day for firm decisions!!!!! Or is it? % A few hours grace before the madness begins again. % A gift of a flower will soon be made to you. % A long-forgotten loved one will appear soon. Buy the negatives at any price. % A tall, dark stranger will have more fun than you. 

然后使用strfile实用程序创建二进制搜索索引(有关其他选项,请参阅其联机帮助页)。 当您将文本文件和二进制索引文件都放在/usr/share/games/fortunes/ ,您的新幸运cookie应该可用。

财富命令记录在这里: man fortune 。 手册页告诉您如何指定自己的命运文件。 默认文件位于/ usr / share / games / fortunes(我通过输入locate fortune找到它们。

如果你想永久地添加你的自定义文件,有几种方法:把它放在/ usr / share / games / fortunes中,为别名做一个别名( help alias )等等。

为了获得自己的自定义幸运cookies,首先要创建一个文件并添加要显示为财富的文本帽子。
在您的文本编辑器中粘贴您要显示的文本(字符串),并在要显示的每个字符串之间必须有%

假设我们正在使用文件名quotes创建报价财富

 sudo nano quotes 

粘贴到您的文本中并像这样编辑

 Limits exist only in your mind! % "Maybe this world is another planet's hell." — Aldous Huxley % "Choices are the hinges of destiny." —Edwin Markham % “Sometimes it's the smallest decisions that can change your life forever." —Keri Russell % “We are the creative force of our life, and through our own decisions rather than our conditions, if we carefully learn to do certain things, we can accomplish those goals.” —Stephen Covey 

保存文件并创建一个dat文件:

 strfile -c % quotes quotes.dat 

这将为您的cookie文件创建一个.dat文件,该文件包含标题结构和每组行的文件偏移表。 这允许随机访问字符串。

看你的财富,做:

 fortune quotes 

要在您输入财富时将Cookie显示为标准幸运cookies,请在/ usr / share / games / fortunes /中添加引号quotes.dat
如果要在自定义幸运cookie文件中添加或减去任何字符串,则需要运行strfile -c % quotes quotes.dat再次创建新的dat文件

你也可以将你的命运添加到bash中,这样当你打开shell时,你的自定义财富就会让你大吃一惊。
nano ~/.bashrc并添加fortune /path/to/quote | lolcat fortune /path/to/quote | lolcat到文件的末尾并保存

现在关闭终端并打开一个新终端以查看它是否正常工作