Centos7安装zsh 和 oh-my-zsh

码农天地 -
Centos7安装zsh 和 oh-my-zsh

Centos7安装zsh 和 oh-my-zsh今天准备给 我的阿里云上的服务器安装一个 zsh 和 oh-my-zsh 美化一下终端, 我记得我有一篇关于 Mac 下安装 oh-my-zsh 配合 iterm2的 文章,和这一篇差不多吧。。概述

众所周知,大部分的Linux发行版的默认命令解释器是Bash。但除此之外,这个星球上的命令解释器多了去了。

相比于默认的 Bash,Zsh 有更多的自定义选项,并支持扩展。因此 Zsh 可以实现更强大的命令补全,命令高亮等一系列酷炫功能

默认的 Zsh 配置有点麻烦。因此一个叫 robbyrussel 的用户在 GitHub 上制作了一个配置文件 oh-my-zsh,这是目前为止最流行的 Zsh 配置:

默认centos 是使用 /bin/bash 这个 可以通过 echo $shello来查看默认的shell , chsh -l查看所有的支持的shell

查看系统支持的 shell chsh -l = cat /etc/shells

跟换系统的shell chsh -s /bin/zsh

有了上面的基础 下面我们开始安装 zsh

1. 安装zsh这里可能会有问题,安装不上,可能需要给centos7 换源,具体换源看 centos 笔记中的 换源操作安装zsh

yum install zsh

2.安装 oh-my-zsh

默认的 Zsh 配置有点麻烦。因此一个叫 robbyrussel 的用户在 GitHub 上制作了一个配置文件 oh-my-zsh,这是目前为止最流行的 Zsh 配置

2.1 安装 install.sh 脚本

可以直接通过

 wget https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh

上面这个可能会有问题,可能无法访问阻塞了

下面使用 wget 通过在gitee 码云上去下载,不过这个要有 git的支持

wget https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh

安装git

如果你的服务器已经有了 git 支持 那就不用安装 ,可以通过 git --version ,如果没有则需要安装 ,详细可以看我的 centos7安装 git 的笔记(安装git 可以从官网下载后 进行make 和 make install 然后配置环境变量 即可)

假设到目录 你已经安装好了git 下面继续安装oh-my-zsh

通过这个命令 成功后

wget https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh

编辑install.sh

# Default settings
ZSH=${ZSH:-~/.oh-my-zsh}
REPO=${REPO:-ohmyzsh/ohmyzsh}
REMOTE=${REMOTE:-https://github.com/${REPO}.git}
BRANCH=${BRANCH:-master}


REPO=${REPO:-ohmyzsh/ohmyzsh}
REMOTE=${REMOTE:-https://github.com/${REPO}.git}

替换为


REPO=${REPO:-mirrors/oh-my-zsh}  #注意这个也有变化 ,其实就是换个地址 和上面wget 一样的gitee地址
REMOTE=${REMOTE:-https://gitee.com/${REPO}.git}

编辑后保存, 运行安装即可. (运行前先给install.sh权限)

赋予可执行权限
chomd +x install.sh
运行
sh install.sh # 这一步后 你的 ~/.oh-my-zsh下面就有了 oh-my-zsh仓库 

修改仓库地址

cd ~/.oh-my-zsh
git remote set-url origin https://gitee.com/mirrors/oh-my-zsh.git
git pull
2. 切换 zsh结合概述中说的, 通过 chsh -s /bin/zsh 来切换 centos的 默认shell

切换zsh shell

chsh -s /bin/zsh
3.安装 oh-my-zsh 主题插件等等3.1 下载 ys.zsh-theme
git clone https://github.com/ss8651twtw/ys.zsh-theme.git ~/.oh-my-zsh/custom/themes/ys.zsh-theme
3.2修改 ./zshrc

ZSH_THEME="ys.zsh-theme/ys"
3.3 刷新 ./zshrc
source ~/.zshrc
3.4 我的效果如下

3.5 扩展修改样式但是我想把 @localhost 去除掉

直接修改 ys.zsh-theme文件

修改前:


PROMPT="
%{$fg[cyan]%}%* 
%(#,%{$bg[red]%}%{$fg[black]%}%n%{$reset_color%},%{$fg[yellow]%}%n) 
%{$fg[white]%}@   删除这行
%{$fg[white]%}%m  删除这行
%{$fg[white]%}in 
%{$terminfo[bold]$fg[green]%}%~%{$reset_color%}
${git_info}
${ret_status}%{$reset_color%}"

修改后:

PROMPT="
%{$fg[cyan]%}%* 
%(#,%{$bg[red]%}%{$fg[black]%}%n%{$reset_color%},%{$fg[yellow]%}%n) 
%{$fg[white]%}in 
%{$terminfo[bold]$fg[green]%}%~%{$reset_color%}
${git_info}
${ret_status}%{$reset_color%}"

最终效果如下:

记得如果是 通过iterm2的Profiles登录,那么可能需要去修改 Color ,否则很难看。。

个人博客:https://www.askajohnny.com 欢迎访问!!
个人公众号: Johnny屋 欢迎关注!!

特别申明:本文内容来源网络,版权归原作者所有,如有侵权请立即与我们联系(cy198701067573@163.com),我们将及时处理。

Tags 标签

加个好友,技术交流

1628738909466805.jpg