1. ZSH 1.1. 安装zsh zsh是一个强大的shell,具有很多强大的功能,如自动补全、语法高亮、命令提示等。
zsh官网:https://www.zsh.org/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 cat /etc/shellsecho $SHELL sudo apt install -y zsh chsh -s $(which zsh) echo $SHELL
1.2. 安装oh-my-zsh oh-my-zsh 是zsh的插件管理器,可以方便的安装各种主题和插件
1 2 3 4 5 6 7 sudo apt install git -y sh -c "$(curl -fsSL https://mirror.ghproxy.com/https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh) " curl -Lo oh-my-zsh.sh https://blog.lololowe.com/file/oh-my-zsh.sh chmod 755 oh-my-zsh.sh./oh-my-zsh.sh
1.3. 安装p10k主题和命令插件 powerlevel10k 是一款灵活,开箱即用的zsh主题
1 2 3 4 5 6 7 8 9 10 11 git clone https://github.com/romkatv/powerlevel10k.git $ZSH_CUSTOM /themes/powerlevel10k git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom} /plugins/zsh-autosuggestions git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom} /plugins/zsh-syntax-highlighting git clone https://ghp.ci/https://github.com/romkatv/powerlevel10k.git $ZSH_CUSTOM /themes/powerlevel10k git clone https://ghp.ci/https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom} /plugins/zsh-autosuggestions git clone https://ghp.ci/https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom} /plugins/zsh-syntax-highlighting
1.4. 安装字体 p10k主题自带的一些图标需要特殊字体支持,推荐使用MesloLGS 字体
如果使用SSH客户端连接SSH服务器,则SSH客户端也需要安装字体 ,否则无法正常显示SSH服务器的图标
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 wget https://mirror.ghproxy.com/https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Regular.ttf && wget https://mirror.ghproxy.com/https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold.ttf && wget https://mirror.ghproxy.com/https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Italic.ttf && wget https://mirror.ghproxy.com/https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold%20Italic.ttf sudo mkdir /usr/share/fonts/truetype/MesloLGS sudo mv *.ttf /usr/share/fonts/truetype/MesloLGS sudo apt install fontconfig fc-cache -fv echo $'\uf115'
1.5. 应用主题和插件 1 2 3 4 5 6 7 8 9 10 11 12 vim ~/.zshrc ZSH_THEME="powerlevel10k/powerlevel10k" plugins=( git zsh-autosuggestions zsh-syntax-highlighting )
编辑并保存后,重启终端即可进入p10k主题的交互式配置向导,也可以执行p10k configure
命令进行配置。
2. Tmux 状态栏 Tmux 是一个终端复用器,具体用法可以参考阮一峰大佬的文章:https://www.ruanyifeng.com/blog/2019/10/tmux.html
Tmux提供了一个状态栏,通过配置Tmux的状态栏,可以使其在终端的顶部实时显示各项硬件参数,如网速、温度、功率、硬件利用率等,如下图:
嫌Tmux配置麻烦可以去用byobu ,启动byobu后直接按F9并选择 “Toggle status notifications”,即可自定义底部状态栏。
2.1. 安装Tmux 1 2 apt update apt install tmux sysstat ifstat lm-sensors -y
2.2. 编写脚本 创建5个获取硬件信息的脚本,并放在/root/shell_scripts
目录下,5个脚本内容分别如下:
2.2.1. CPU利用率获取脚本 cpu_usage.sh
1 2 #!/bin/bash mpstat 1 1 | awk 'NR==4 {printf "CPU: %.1f%%", 100 - $12}'
2.2.2. 内存利用率获取脚本 memory_usage.sh
1 2 #!/bin/bash free | awk 'NR==2 {printf "Mem: %.1f%%", ($2 - $4)/$2 * 100.0}'
2.2.3. 上下行网速获取脚本 net_speed.sh
1 2 #!/bin/bash ifstat -S 1 1 | awk 'NR==3 {printf "D: %.2f MB/s | U: %.2f MB/s", $1 / 1024, $2 / 1024}'
如果上行网速获取不对,可以修改脚本内容为以下:
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 36 37 interface=${interface##*/} if [[ ! " ${excluded_interfaces[@]} " =~ " ${interface} " ]]; then if [[ -d "${network_dir} /${interface} /statistics" ]]; then rx_bytes=$(cat "${network_dir} /${interface} /statistics/rx_bytes" ) tx_bytes=$(cat "${network_dir} /${interface} /statistics/tx_bytes" ) total_rx_bytes_current=$((total_rx_bytes_current + rx_bytes)) total_tx_bytes_current=$((total_tx_bytes_current + tx_bytes)) fi fi done read prev_time total_rx_bytes_previous total_tx_bytes_previous < "$stats_file " interval=$((current_time - prev_time)) if (( interval > 0 )); then rx_bytes_delta=$(( total_rx_bytes_current - total_rx_bytes_previous )) tx_bytes_delta=$(( total_tx_bytes_current - total_tx_bytes_previous )) tx_bytes_per_sec=$(( tx_bytes_delta / interval )) else rx_bytes_per_sec=0 tx_bytes_per_sec=0 fi else rx_bytes_per_sec=0 tx_bytes_per_sec=0 fi echo "${current_time} ${total_rx_bytes_current} ${total_tx_bytes_current} " > "$stats_file " printf "D: %.2f MB/s | U: %.2f MB/s\n" "$(echo "scale=2; $rx_bytes_per_sec / 2 / 1024 / 1024" | bc) " "$(echo "scale=2; $tx_bytes_per_sec / 2 / 1024 / 1024" | bc) "
2.2.4. CPU+GPU功率获取脚本 power_usage.sh
1 2 3 #!/bin/bash sleep 1sensors | grep -i "PPT" | awk '{print "PPT: " $2}' | sed 's/W//'
2.2.5. CPU和GPU温度获取脚本 temperature.sh
1 2 3 4 5 #!/bin/bash cpu_temp=$(sensors | grep 'Tctl' | awk '{print $2}' ) gpu_temp=$(sensors | grep 'edge' | awk '{print $2}' ) echo "CPU: $cpu_temp , GPU: $gpu_temp "
创建完5个脚本之后,编辑Tmux配置文件~/.tmux.conf
,将5个脚本添加到Tmux状态栏配置中,配置如下:
1 2 3 4 5 6 7 8 9 set -g status onset -g status-interval 2set -g status-position topset -g mouse onset -g status-bg colour8set -g status-fg whiteset -g status-right-length 120set -g status-right '#(/root/shell_scripts/net_speed.sh) | #(/root/shell_scripts/temperature.sh) | #(/root/shell_scripts/power_usage.sh) | #(/root/shell_scripts/memory_usage.sh) | #(/root/shell_scripts/cpu_usage.sh) | #(date +"%Y-%m-%d %H:%M")'
保存配置文件后,使用 tmux source-file ~/.tmux.conf
命令重载配置即可看到状态栏。
为了进入终端后能自动启动Tmux,可以编辑~/.zshrc
文件,追加以下内容:
1 2 3 4 if command -v tmux>/dev/null; then [ -z "$TMUX " ] && exec tmux fi
3. 下一代ls命令 lsd 是一个更美观的ls命令,可以替代默认的ls命令,如下图:
注意:安装lsd之前需要参考上文安装第三方字体,否则lsd的图标会显示为乱码。
安装:
1 2 3 4 5 6 wget https://github.com/lsd-rs/lsd/releases/download/v1.1.5/lsd-musl_1.1.5_amd64_xz.deb -o /tmp/lsd.deb wget https://ghp.ci/https://github.com/lsd-rs/lsd/releases/download/v1.1.5/lsd-musl_1.1.5_amd64_xz.deb -O /tmp/lsd.deb sudo apt install /tmp/lsd.deb lsd -V
编辑配置文件,修改默认的ls命令为lsd
1 2 echo "alias ll='lsd -lh'\nalias la='lsd -alh'" >> ~/.zshrcsource ~/.zshrc
由于将其它命令写在了p10k的配置命令下面,会导致登陆终端时出现警告,因此需要执行以下命令忽略警告
1 2 echo "typeset -g POWERLEVEL9K_INSTANT_PROMPT=quiet" >> ~/.zshrcsource ~/.zshrc
4. cat命令输出高亮 bat 是一个带语法高亮的的cat命令,可以替代默认的cat命令,如下图:
安装:
编辑配置文件,修改默认的cat命令为batcat:
1 2 echo "alias cat=batcat" >> ~/.zshrcsource ~/.zshrc
如果需要输出不带行号,可以执行以下命令修改mat的配置文件:
1 echo --style = plain >> ~/.config/bat/config
5. fastfetch显示系统信息 fastfetch是一个持续维护、功能丰富、面向性能、类似 neofetch 的系统信息展示工具。效果如下图:
安装:
1 2 3 4 5 6 wget https://github.com/fastfetch-cli/fastfetch/releases/download/2.30.1/fastfetch-linux-amd64.deb -O /tmp/fastfetch.deb wget https://ghp.ci/https://github.com/fastfetch-cli/fastfetch/releases/download/2.30.1/fastfetch-linux-amd64.deb -O /tmp/fastfetch.deb sudo apt install /tmp/fastfetch.deb fastfetch -V
编辑配置文件,使用户登陆终端时显示系统信息
1 echo "fastfetch --pipe false" >> ~/.zshrc
完善显示的内容(机器没网不要改,会导致进入终端时卡住):
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 { "$schema " : "https://ghp.ci/https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json" , "modules" : [ "title" , "separator" , "os" , "host" , "kernel" , "uptime" , "packages" , "shell" , "display" , "de" , "wm" , "wmtheme" , "cpu" , "gpu" , "memory" , "swap" , "disk" , "localip" , "publicip" , "dns" , "battery" , "poweradapter" , "locale" , "break" , "colors" ] }
6. 删除登录提示 删除最后一次登录ssh的提示信息:
1 2 sudo sed -i 's/#PrintLastLog yes/PrintLastLog no/g' /etc/ssh/sshd_config sudo systemctl restart sshd
删除登录提示信息:
1 2 3 session optional pam_motd.so motd=/run/motd.dynamic session optional pam_motd.so noupdate
重启sshd服务:
1 sudo systemctl restart sshd
7. 中文语言环境 向导式配置:dpkg-reconfigure locales
手动配置:
1 2 sudo sed -i 's/# zh_CN.UTF-8 UTF-8/zh_CN.UTF-8 UTF-8/g' /etc/locale.gen locale-gen
vim 编辑 /etc/default/locale 文件,替换为以下内容:
1 2 3 LANG=zh_CN.UTF-8 LANGUAGE="zh_CN:zh"
载入语言环境:
1 2 source /etc/default/localedate
vim 显示中文(解决中文乱码问题):
1 2 3 4 5 set nuset termencoding=utf-8set encoding=utf8set fileencodings=utf8,ucs-bom,gbk,cp936,gb2312,gb18030
8. 实用终端工具推荐
9. 参考