1.安装zsh
sudo pacman -S zsh
2.设置默认zsh
列出所有已安装shell
chsh -l
要为您的用户设置一个默认值
chsh -s /full/path/to/shell
例如
chsh -l /usr/bin/bash
3.注销并再次登录,打开shell
这时会看到zsh ,并新手任务
如下
This is the Z Shell configuration function for new users,
zsh-newuser-install.
You are seeing this message because you have no zsh startup files
(the files .zshenv, .zprofile, .zshrc, .zlogin in the directory
~). This function can help you with a few settings that should
make your use of the shell easier.
You can:
(q) Quit and do nothing. The function will be run again next time.
(0) Exit, creating the file ~/.zshrc containing just a comment.
That will prevent this function being run again.
(1) Continue to the main menu.
--- Type one of the keys in parentheses ---
输入0就会退出并获得新手任务奖励配置文件~/.zshrc
4.安装插件
sudo pacman -S zsh-autosuggestions zsh-completions zsh-history-substring-search zsh-syntax-highlighting
zsh-autosuggestions 给出补全建议
zsh-completion 应该是强化补全吧
zsh-history-substring-search 输入一部分命令后根据历史补全,需要快捷键
zsh-syntax-highlighting 语法高亮 目前我知道正确是绿色 错误是红色
5.设置配置
vim ~/.zshrc
在~/.zshrc中输入以下配置
# 插件
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/zsh/plugins/zsh-history-substring-search/zsh-history-substring-search.zsh
# 配置
PROMPT='%F{13}[%n@%m %#]%f'
# 历史记录
HISTFILE=~/.histfile
HISTSIZE=1000
SAVEHIST=1000
# 快捷键
bindkey '^P' history-search-backward
bindkey '^N' history-search-forward
# 设置标题
autoload -Uz add-zsh-hook
function xterm_title_precmd () {
print -Pn -- '\e]2; %~\a'
[[ "$TERM" == 'screen'* ]] && print -Pn -- '\e_\005{g}%n\005{-}@\005{m}%m\005{-} \005{B}%~\005{-}\e\\'
}
function xterm_title_preexec () {
print -Pn -- '\e]2; %~ %# ' && print -n -- "${(q)1}\a"
[[ "$TERM" == 'screen'* ]] && { print -Pn -- '\e_\005{g}%n\005{-}@\005{m}%m\005{-} \005{B}%~\005{-} %# ' && print -n -- "${(q)1}\e\\"; }
}
if [[ "$TERM" == (Eter
配置这一项是设置命令提示符,显示用户名主机名 权限
历史记录是设置记录命令输入历史
快捷键是在输入部分命令后用ctrl+n ctrl+p键根据历史命令记录进行补全
设置标题显示工作路径 权限和命令