注意
本文最后更新于 2023-07-31,文中内容可能已过时。
安装zsh(Debian10)
查看当前 shell:echo $SHELL
查看系统中安装了哪些 shell:cat /etc/shells
切换 shell 环境:chsh -s /bin/zsh
安装:apt install zsh
安装 zsh 插件
zsh-autosuggestions
:这个是自动建议插件,能够自动提示你需要的命令。根据历史命令提示
zsh-syntax-highlighting
:这个是代码高亮插件,能够使你的命令行各个命令清晰明了。
zsh-completions
:命令自动补全。感觉不是很好用,看个人情况,不推荐安装。
1
2
3
4
5
6
7
8
|
git clone https://github.com/zsh-users/zsh-autosuggestions /usr/local/zsh-plugins/zsh-autosuggestions # 自动补全
git clone https://github.com/zsh-users/zsh-syntax-highlighting /usr/local/zsh-plugins/zsh-syntax-highlighting # 语法高亮
git clone --depth=1 https://github.com/zsh-users/zsh-completions.git /usr/local/zsh-completions # 命令选项自动补齐,不太好使
# 我fork的仓库,使用ssh连接
git clone git@github.com:BluefoxQAQ/zsh-autosuggestions.git /usr/local/zsh-plugins/zsh-autosuggestions
git clone git@github.com:BluefoxQAQ/zsh-syntax-highlighting.git /usr/local/zsh-plugins/zsh-syntax-highlighting
git clone git@github.com:BluefoxQAQ/zsh-completions.git /usr/local/zsh-completions
|
zsh的配置
这是我目前正在使用的zsh配置文件,可以直接复制使用
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# PS1='[\[\e[1;35;1m\]\t \[\e[1;32;1m\]\u@\H \[\e[1;33;1m\]\w] \n \$ \[\e[1;37;1m\]' # 废弃,不好看
# PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' # bash用这个
# export PS1="%10F%m%f:%11F%1~%f \$ " # zsh用这个
# export PS1='%F{#00ffff}%B%n@%m%b%f:%B%F{#00afff}%~%f%#%b ' # zsh用这个
# export PS1=$'%F{#00ffff}%B%n@%m%b%f:%B%F{#00afff}%~%f%b\n>%# ' # zsh用这个
export PS1=$'%F{#00ffff}%B%n@%m%b%f:%B%F{#00afff}%~%f%b\n %F{#ffff00}>%#%b%f ' # zsh用这个,双行
alias ls='ls --color'
alias grep='grep --color=auto'
export GREP_COLOR="1;31"
export LS_COLORS='rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:'
# 启用插件
source /usr/local/zsh-plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
source /usr/local/zsh-plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
# fpath=(/usr/local/zsh-completions/src $fpath) # 命令选项自动补齐,不用
# autoload -Uz compinit && compinit
# 启用彩色提示符
autoload -U colors && colors
# 每次刷新提示符
setopt prompt_subst
# 设置提示符
# PROMPT='❰%{$fg[green]%}%n%{$reset_color%}|%{$fg[yellow]%}%1~%{$reset_color%}%{$fg[blue]%}$(git branch --show-current 2&> /dev/null | xargs -I branch echo "(branch)")%{$reset_color%}❱ '
# zsh历史命令存储
HISTFILE="$HOME/.zsh_history"
HISTSIZE=10000000
SAVEHIST=10000000
setopt BANG_HIST # Treat the '!' character specially during expansion.
setopt EXTENDED_HISTORY # Write the history file in the ":start:elapsed;command" format.
setopt INC_APPEND_HISTORY # Write to the history file immediately, not when the shell exits.
setopt SHARE_HISTORY # Share history between all sessions.
setopt HIST_EXPIRE_DUPS_FIRST # Expire duplicate entries first when trimming history.
setopt HIST_IGNORE_DUPS # Don't record an entry that was just recorded again.
setopt HIST_IGNORE_ALL_DUPS # Delete old recorded entry if new entry is a duplicate.
setopt HIST_FIND_NO_DUPS # Do not display a line previously found.
setopt HIST_IGNORE_SPACE # Don't record an entry starting with a space.
setopt HIST_SAVE_NO_DUPS # Don't write duplicate entries in the history file.
setopt HIST_REDUCE_BLANKS # Remove superfluous blanks before recording entry.
setopt HIST_VERIFY # Don't execute immediately upon history expansion.
setopt HIST_BEEP # Beep when accessing nonexistent history.
# 命令选项自动补齐,不太好使
#_proxy(){
# local cur cword words # 定义变量,cur表示当前光标下的单词
# read -cn cword # 所有指令集
# read -Ac words # 当前指令的索引值
# cur="$words[$cword-1]" # 当前指令值
# if [ $cur = "proxy" ] # 根据当前不同指令返回对应的提示信息
# then
# reply=(start stop restart connect route help) # 必须是值reply,返回提示信息内容
# elif [ $cur = "route" ]
# then
# reply=(add delete)
# else
# reply=()
# fi
#}
# compctl -K _proxy proxy # -K 表示使用函数
# enable completion features
# autoload -Uz compinit
# compinit -d ./zcompdump
|