首页 专题 文章 代码 归档

[Share]更换Centos默认的Shell为zsh

1. 安装zsh

sudo yum install zsh -y

截图-1588405332

现在zsh已经安装完成了,需要把系统默认的shell由bash切换为zsh

切换shell至zsh,代码如下:

chsh -s /bin/zsh  #

重启系统:

sudo reboot

再来看:

echo $SHELL

就换过来了:

2. 安装oh-my-zsh

oh-my-zsh是一个增强zsh的工具,异常强大!

先要安装git,因为oh-my-zsh是GitHub上的开源项目,要使用必须先下载到本地;

sudo yum install git -y

安装oh-my-zsh有两种方法,curl或wget,二选一即可(哪个成功用哪个):

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O - | sh

成功界面:

截图-1588405793

3. 配置主题

主题地址:

https://github.com/ohmyzsh/ohmyzsh/wiki/themes

找到主题名称,然后修改文件:

vim ~/.zshrc

刚安装oh-my-zsh默认的主题是robbyrussell,将ZSH_THEME改成你要想的主题名称即可。

修改完主题后,再次重启即可!

4. 安装插件

主题好看之外,其实安装一些插件也是非常有必要的,推荐哪些插件?

可以看知乎该回答:

https://www.zhihu.com/question/49284484?sort=created

查看自带有哪些插件:

➜  plugins git:(master) cd ~/.oh-my-zsh/plugins 
➜  plugins git:(master) ls -d *
adb                dirpersist         gulp                      per-directory-history  svn-fast-info
ant                django             heroku                    perl                   swiftpm
apache2-macports   dnf                history                   perms                  symfony
arcanist           docker             history-substring-search  phing                  symfony2
archlinux          docker-compose     httpie                    pip                    systemadmin

选择要激活的插件到:~/.zshrc

修改plugins配置:

plugins=(git zsh-autosuggestions)

4.1. zsh-autosuggestions

git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions

自动提示历史命令的插件

然后添加到

vim ~/.zshrc

的plugins配置就行:

截图-1588406668

我这里配置了两个:

中间以空格分开:

plugins=(git zsh-autosuggestions)

5. 解决Home/End键问题

默认使用了zsh,那么Home和End键使用是有问题的,在.zshrc文件中添加如下代码即可:

# key bindings
bindkey "\e[1~" beginning-of-line
bindkey "\e[4~" end-of-line
bindkey "\e[5~" beginning-of-history
bindkey "\e[6~" end-of-history
bindkey "\e[3~" delete-char
bindkey "\e[2~" quoted-insert
bindkey "\e[5C" forward-word
bindkey "\eOc" emacs-forward-word
bindkey "\e[5D" backward-word
bindkey "\eOd" emacs-backward-word
bindkey "\ee[C" forward-word
bindkey "\ee[D" backward-word
bindkey "^H" backward-delete-word
# for rxvt
bindkey "\e[8~" end-of-line
bindkey "\e[7~" beginning-of-line
# for non RH/Debian xterm, can't hurt for RH/DEbian xterm
bindkey "\eOH" beginning-of-line
bindkey "\eOF" end-of-line
# for freebsd console
bindkey "\e[H" beginning-of-line
bindkey "\e[F" end-of-line
# completion in the middle of a line
bindkey '^i' expand-or-complete-prefix
此文阅读完毕,您可以:分享
二维码图片 扫描关注我们哟