跳到主要内容

「MacBook 终端美化」牛牛对你说!

· 阅读需 2 分钟

安装插件

首先安装两个插件

brew install cowsay
brew install fortune

执行命令

fortune | cowsay

就会得到如下的效果

修改知识库

默认情况下是英语,可以调整它的🧀知识库。github上有开源的知识库:https://github.com/ruanyf/fortunes

  1. 先将知识库克隆下来:git clone https://github.com/ruanyf/fortunes.git

  2. 用strfile为知识库文件创建索引文件

    strfile fortunes/data/fortunes
    strfile fortunes/data/chinese
    strfile fortunes/data/tang300
    strfile fortunes/data/song100
    strfile fortunes/data/diet
  3. 默认知识库的位置:/usr/local/share/games/fortunes ,可以选择清空默认的数据库,我清空了

  4. 将上面的知识库文件拷贝过来

    cp fortunes/data/* /usr/local/share/games/fortunes/
  5. 测试

    ❯ fortune | cowsay
    _________________________________________
    / 心事浩茫连广宇,于无声处听 \
    | 惊雷。 |
    | |
    \     - 鲁讯 /
    -----------------------------------------
    \ ^__^
    \ (oo)\_______
    (__)\ )\/\
    ||----w |
    || ||

配合 On My Zsh

在 .zshrc 配置文件中,追加

fortune | cowsay

刷新配置

source .zshrc

使用Powerlevel10k主题的话每次启动会提示

[WARNING]: Console output during zsh initialization detected.

When using Powerlevel10k with instant prompt, console output during zsh
initialization may indicate issues.

You can:

- Recommended: Change ~/.zshrc so that it does not perform console I/O
after the instant prompt preamble. See the link below for details.

* You will not see this error message again.
* Zsh will start quickly and prompt will update smoothly.

- Suppress this warning either by running p10k configure or by manually
defining the following parameter:

typeset -g POWERLEVEL9K_INSTANT_PROMPT=quiet

* You will not see this error message again.
* Zsh will start quickly but prompt will jump down after initialization.

- Disable instant prompt either by running p10k configure or by manually
defining the following parameter:

typeset -g POWERLEVEL9K_INSTANT_PROMPT=off

* You will not see this error message again.
* Zsh will start slowly.

- Do nothing.

* You will see this error message every time you start zsh.
* Zsh will start quickly but prompt will jump down after initialization.

For details, see:
https://github.com/romkatv/powerlevel10k/blob/master/README.md#instant-prompt

-- console output produced during zsh initialization follows --

重新配置主题

p10k configure

到下面这一步「Instant Prompt Mode」的时候选择Off! 即可。

附:终端自定义 banner

修改/etc/motd这个文件 。(motd 是message of the day的缩写,意思是“当天的提示信息”,通常在用户成功登录后出现,该信息可以从/etc/motd文本文件中找到)

    へ     /|
  /\7   ∠_/
  / │   / /
 │ Z _,< /   /`
 │     ヽ   /  〉
  Y     `  /  /
 イ● 、 ●  ⊂⊃〈  /
 ()  v    | \〈
  >ー 、_  ィ  │ //
  / へ   / ノ<| \\
  ヽ_ノ  (_/  │//
  7       |
  >―r ̄ ̄`ー―_- Hello World! Good good study ,day day up!

效果:

Last login: 21:44:09 on ttys000
へ     /|
  /\7   ∠_/
  / │   / /
 │ Z _,< /   /`
 │     ヽ   /  〉
  Y     `  /  /
 イ● 、 ●  ⊂⊃〈  /
 ()  v    | \〈
  >ー 、_  ィ  │ //
  / へ   / ノ<| \\
  ヽ_ノ  (_/  │//
  7       |
  >―r ̄ ̄`ー―_- Hello World! Good good study ,day day up!