zsh beautification - pop up a famous saying every time you open the terminal (one sentence)

First look at the effect, as follows

 My zsh is p10k theme with hitokoto plugin added

The p10k theme configuration and font installation will not be introduced. Other themes can also achieve the effect of opening the terminal to display famous quotes. Let’s start with the introduction.

1. Add hitokoto plugin in zsh

This plug-in is a built-in plug-in of zsh, which can be added directly in zshrc and plugins. The command is as follows

open zshrc

sudo gedit ~/.zshrc

find the content

plugins=(git)

Add the plugin, the final result is as follows

plugins=(git hitokoto)

2. Install dependencies

Before that, you need to install curl to use it normally, the command is as follows

sudo apt-get install curl

3. Configure zshrc

3.1 In the first solution, when you open the terminal, a famous saying pops up, and it does not pop up at other times

In zshrc, add the following

curl https://v1.hitokoto.cn/ &>.Yi.txt
echo -e "\e[32m[$(date +"%F %T")] ""$(cat .Yi.txt|grep hitokoto |awk -F: '{print $4}'| awk -F, '{print $1}')"" \e[0m"

If you are using p10k, you will be prompted with a message pop-up window every time you open it. The command to close the p10k theme warning is as follows, and add it to zshrc

typeset -g POWERLEVEL9K_INSTANT_PROMPT=off

Save zshrc, and then reopen the terminal to have the above effect.

3.2 Scheme 2, display a famous quote every time a command is executed (not recommended)

Because it is downloaded (climbed) from the Yiyan website, there will be a delay every time you open it. It depends on your network situation. The configuration is as follows.

Copy the content of the first scheme into the square brackets of precmd(){}. The complete content is as follows

precmd(){
curl https://v1.hitokoto.cn/ &>~/.Yi.txt
echo -e "\e[32m[$(date +"%F %T")] ""$(cat ~/.Yi.txt|grep hitokoto |awk -F: '{print $4}'| awk -F, '{print $1}')"" \e[0m"
}

After the configuration is completed, I am very happy, and the work efficiency has improved again, which is great.

Guess you like

Origin blog.csdn.net/qq_36076137/article/details/127128920