zsh安装与配置
前言:
为了方便配置与使用zsh,并且减少更换电脑的时候配置linux环境所花费的时间,在这里记录zsh的安装与配置所使用的指令。注意:本教程在archlinux环境下进行。
安装:
在linux当中使用相对应的包管理软件进行安装,下面展示 archlinux 的安装与相对应的zsh插件配置:
sudo pacman -S zsh
配置:
配置包括常用插件,zsh 设置
- 常用插件:
- community/zsh-syntax-highlighting
- 语法高亮
- community/zsh-lovers
- community/zsh-history-substring-search
- community/zsh-completions
- community/zsh-autosuggestions
- community/zsh-syntax-highlighting
为了可以正常使用,切换bash到zsh:
chsh -s /usr/bin/zsh
安装上面的插件:
sudo pacman -S zsh-syntax-highlighting zsh-lovers zsh-completions zsh-autosuggestions fzf
为了方便设置,顺便使用一个oh-my-zsh的框架,这里使用yay 进行 aur 仓库管理,倘若没有,需要添加archlinuxcn软件源,安装一个 AUR 库管理工具:
- 编辑 /etc/pacman.d
- 添加下面内容到文件底部:
[archlinuxcn]
SigLevel = Optional TrustAll
Server = http://repo.archlinuxcn.org/$arch
- 保存,更新软件包信息:
sudo pacman -Sy
- 然后安装 yay 包
sudo pacman -S yay
- 安装oh-my-zsh
yay oh-my-zsh
下面是正常使用的配置文件,当中的内容分别从 oh-my-zsh当中的zshrc 提取和我自己编写,我自己编写内容参考了部分网络内容(比如archlinux wiki当中关于zsh 的介绍.)
# zsh config
HISTFILE=~/.cache/zsh_history
HISTSIZE=5000
SAVEHIST=10000
# Path to your oh-my-zsh installation.
ZSH=/usr/share/oh-my-zsh/
# 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="dst"
# 我比较喜欢使用这个zsh主题,其中的命令位置对齐,方便查找。
# 下面是oh-my-zsh的插件,具体使用那些见 /usr/share/oh-my-zsh/scripts 当中的内容。
plugins=(
git
adb
fd
screen
man
fzf
sudo
systemd
cp
python
pyenv
)
ZSH_CACHE_DIR=$HOME/.cache/oh-my-zsh
if [[ ! -d $ZSH_CACHE_DIR ]]; then
mkdir $ZSH_CACHE_DIR
fi
source $ZSH/oh-my-zsh.sh
setopt printexitvalue
setopt CORRECT
setopt CORRECT_ALL
autoload -U colors
# colors
# Simple Prompt username@hostname dir %
setopt prompt_subst
# PROMPT='%F{blue}%n%f@%m %2~ %# '
# use autocde
setopt autocd
# Use Vim keybindings
bindkey -v
# Completion
zstyle ':completion:*' menu select
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
autoload -Uz compinit
compinit
# alias
alias grep='grep --colour=auto'
alias egrep='egrep --colour=auto'
alias fgrep='fgrep --colour=auto'
alias ls='ls --color=auto --human-readable --group-directories-first --classify'
alias ll='ls --color=auto --human-readable --group-directories-first --classify -l'
alias la='ls --color=auto --human-readable --group-directories-first --classify -la'
alias vim=nvim
alias vi=nvim
alias parui="paru -Slq | fzf --multi --preview 'paru -Si {1}' | xargs -ro paru -S"
alias parur="paru -Qq | fzf --multi --preview 'paru -Qi {1}' | xargs -ro paru -Rns"
if [[ "$TERM" == "xterm-kitty" ]] then
alias ssh="kitty +kitten ssh"
fi
# functions
man() {
env \
LESS_TERMCAP_mb=$(printf "\e[1;31m") \
LESS_TERMCAP_md=$(printf "\e[1;31m") \
LESS_TERMCAP_me=$(printf "\e[0m") \
LESS_TERMCAP_se=$(printf "\e[0m") \
LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
LESS_TERMCAP_ue=$(printf "\e[0m") \
LESS_TERMCAP_us=$(printf "\e[1;32m") \
man "$@"
}
# source some plugins
source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
source /usr/share/fzf/key-bindings.zsh
source /usr/share/fzf/completion.zsh
source /usr/share/zsh/plugins/zsh-history-substring-search/zsh-history-substring-search.zsh