我的Linux生活日記 03-建立一個友善的終端機人機介面
既然都安裝Lunx而且畢生都得跟Linux 為伍,必須得跟文字介面為伍。但是我記性偏偏不好,大腦記憶體只有256KB少的可憐,所以安裝完Linux第一件事情是優化文字介面。
安裝必要套件
sudo apt -y install curl wget git
下載字型
下載 Meslo Nerd Font 讓 terminal 可以正常顯示icon
sudo mkdir -p /usr/local/share/fonts/custom
sudo wget -P /usr/share/fonts/custom https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Regular.ttf
sudo wget -P /usr/share/fonts/custom https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Bold.ttf
sudo wget -P /usr/share/fonts/custom https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS%20NF%20Italic.ttf
sudo fc-cache -v -f
安裝 Tabby terminal
-
官方網站: https://tabby.sh/
-
安裝指令
curl -s https://packagecloud.io/install/repositories/eugeny/tabby/script.deb.sh | sudo bash
sudo apt install tabby-terminal
設定字型為 MesloLGS NF
安裝 zsh
- 安裝指令
# Debian
sudo apt install zsh
# Redhat
sudo dnf install zsh
- 預設
zsh
為殼層
chsh -s $(/usr/bin/zsh)
sudo chsh -s /usr/bin/zsh
安裝 autojump
# Debian
sudo apt install autojump
# Redhat
sudo dnf install autojump
安裝 Oh-my-zsh
下載並安裝 Oh-my-zsh
重新登入後生效
- 安裝指令
sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
下載plugin
tab 自動完成: zsh-completions
- 安裝指令
git clone https://github.com/zsh-users/zsh-completions ${ZSH_CUSTOM:=~/.oh-my-zsh/custom}/plugins/zsh-completions
- 更新指令
git -C ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/zsh-completions pull
自動補全: zsh-autosuggestions
會依據歷史紀錄預覽顯示,效果如圖
- 安裝指令
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
- 更新指令
git -C ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/zsh-autosuggestions pull
高亮度語法: zsh-syntax-highlighting
可以輕易識別一行指令中的組成成份,上面是原始,下面是套用過的效果。
- 安裝指令
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
- 更新指令
git -C ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/zsh-syntax-highlighting pull
powerlevel10k
可以漂亮顯示當前目錄的狀態。
- 安裝指令
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
- 更新指令
git -C ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k pull
設定 oh-my-zsh
下載完成之後,接下來就是配置設定啦。首先我們先編輯 .zshrc
文件。
- ~/.zshrc
... 部份省略
# 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/ohmyzsh/ohmyzsh/wiki/Themes
# ZSH_THEME="robbyrussell"
# 異動內容
ZSH_THEME="powerlevel10k/powerlevel10k"
... 部份省略
# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
# 異動內容
plugins=(
git
zsh-syntax-highlighting
zsh-autosuggestions
zsh-completions
autojump
)
... 部份省略
alias history="history -i"
# How many commands to store in history
HISTSIZE=10000
SAVEHIST=100000
# History file for zsh
HISTFILE=~/.zsh_history
setopt INC_APPEND_HISTORY
# Share history in every terminal session
setopt SHARE_HISTORY
setopt HIST_EXPIRE_DUPS_FIRST
setopt HIST_IGNORE_SPACE
setopt EXTENDED_HISTORY
- 套用設定
配置完 .zshrc
文件之後就是跑 powerlevel10k
設定啦!
source ~/.zshrc
接下來就會自動引導設定
經過一系列喜好設定這就是我自己喜歡的樣式
如果之後想改樣powerlevel10k樣式設定執行下列命令就可以了。
p10k configure
有趣的小功能
sudo apt install -y cowsay sl cmatrix sysvbanner figlet
- ~/.zshrc
alias cowsay=/usr/games/cowsay
alias sl=/usr/games/sl
cowsay 測試
sl
cmatrix -r
banner Test
figlet Test