让你的zsh躁起来

近来频繁看到GitHub上分享的个人dotfile的readme页面出现一副ASCII画面主导的系统信息,仔细观察发现是Neofetch ,据官方介绍,是一种「用bash3.2+写的、基于命令行的系统信息工具」,同类的还有screenfetch。

什么是neofetch

Neofetch is a command-line system information tool written in bash 3.2+. Neofetch displays information about your operating system, software and hardware in an aesthetic and visually pleasing way.

The overall purpose of Neofetch is to be used in screen-shots of your system. Neofetch shows the information other people want to see. There are other tools available for proper system statistic/diagnostics.

如何安装neofetch

以macOS为例,如果你安装了Homebrew,那么16个字符就能轻松搞定

$ brew install zsh

完成后就可以运行neofetch命令了,但为了让neofetch能随zsh启动,先修改zsh配置

$ vi ~/.zshrc

在你的zsh启动主题后面添加neofetch(另一种写法是末尾加载)

 # Set name of the theme to load --- if set to "random", it will
 # load a random theme each time oh-my-zsh is loaded, in which case,
 # to know which specific one was loaded, run: echo $RANDOM_THEME
 # See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
 ZSH_THEME="ys"
 neofetch

也可以前置一个判断逻辑:

1 - » 获取neofetch路径

which neofetch

2 - » 在zsh配置中加载

if [ -x /usr/bin/neofetch ]
then
    /usr/bin/neofetch
fi

好了,重启zsh就可以看到效果了。

如何配置neofetch

如果需要个性化定制配置文件,修改如下文件:

$ vi ~/.config/neofetch/config.conf

基本设置信息如下,需要开启哪一项,就将前面的注释符#去掉:

print_info () {
    info title
    info underline

    info "Host" model
    info "OS" distro
    info "Kernel" kernel
    info "Uptime" uptime
    info "Packages" packages
    info "Shell" shell
    info "Resolution" resolution
    info "DE" de
    info "WM" wm
    info "WM Theme" wm_theme
    info "Theme" theme
    info "Icons" icons
    info "Terminal" term
    info "Terminal Font" term_font
    info "CPU" cpu
    info "GPU" gpu
    info "Memory" memory

    # The lines below with a '#' in front are additional info functions
    # that are disabled by default. Removing the '#' enables them and adding
    # a '#' to the start disables them again. You can add a '#' to any of the
    # lines in this function to disable their output.

    # info "CPU Usage" cpu_usage
    # info "Disk" disk
    # info "Battery" battery
    # info "Font" font
    # info "Song" song
    # info "Local IP" local_ip
    # info "Public IP" public_ip
    # info "Users" users
    # info "Birthday" birthday

    info cols
}

很多人关心如何替换默认的ASCII logo,比如将苹果logo替换为xubuntu logo,输入:

neofetch --ascii_distro xubuntu

想要了解更多neofetch的帮助信息,输入:

$ neofetch --help