ubuntu使用oh my zsh美化终端
文章目录
- ubuntu使用oh my zsh美化终端
- 1. 安装zsh和oh my zsh
- 2. 修改zsh主题
- 3. 安装zsh插件
- 4. 将`.bashrc`移植到`.zshrc`
- Reference
1. 安装zsh和oh my zsh
首先安装zsh
sudo apt install zsh
然后查看本地有哪些shell可以使用
cat /etc/shells
将默认的shell切换为zsh
chsh -s /bin/zsh
然后安装oh-my-zsh,参考官网提供的两种安装方式
sh -c "$(wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"
或者
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
2. 修改zsh主题
oh-my-zsh内置了很多主题,可以进入路径~/.oh-my-zsh/themes
下进行查看,如图所示
如果想要修改成自己喜欢的主题,可以
sudo gedit ~/.zshrc
然后找到ZSH_THEME="xxxx"
,将其修改为已经安装的主题就行,保存然后退出,打开终端
source ~/.zshrc
这里推荐一个主题powerlevel10k,只需要将其git到~/.oh-my-zsh/custom/themes/powerlevel10k
目录下即可,
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
然后再配置~/.zshrc
文件
sudo gedit ~/.zshrc
修改为ZSH_THEME="powerlevel10k/powerlevel10k"
,然后source
source ~/.zshrc
效果如下
3. 安装zsh插件
zsh的内置插件可以在路径~/.oh-my-zsh/plugins
中进行查看,如下图所示
别的插件可以在:awesome-zsh-plugins进行查找
这里推荐两个插件,第一个是支持自动补全的zsh-autosuggestions
zsh-autosuggestions
我们只需要将其git到路径~/.oh-my-zsh/custom/plugins
中,然后配置~/.zshrc
文件即可
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
然后在~/.zshrc
中把插件添加到插件列表中
plugins=(
# other plugins...
zsh-autosuggestions # 插件之间使用空格隔开
)
然后source一下
source ~/.zshrc
zsh-syntax-highlighting 是一个命令语法校验插件,在输入命令的过程中,若指令不合法,则指令显示为红色,若指令合法就会显示为绿色。
按照相同的流程,我们即可配置这个插件,将其git到~/.oh-my-zsh/custom/plugins
中
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
然后在~/.zshrc
中将zsh-syntax-highlighting插入插件列表
plugins=(
# other plugins...
zsh-autosuggestions
zsh-syntax-highlighting
)
然后source一下
source ~/.zshrc
4. 将.bashrc
移植到.zshrc
笔者之前一直在使用bash
然后配置了一些资源路径,比如ros
、anaconda
还有一些别的环境变量比如cuda
、cudnn
等,要进行移植其实很简单,大部分的时候我们只需要将xxx.bash
替换为xxx.zsh
即可,然后别的一些环境变量的设置可以直接复制过去。举个例子
这是我的.bashrc
自己添加的部分
# >>> clash <<<
export PATH=$PATH:/opt/clash
# >>> cuda <<<
export PATH=$PATH:/usr/local/cuda/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/cuda/lib64
# export CUDA_HOME=/usr/local/cuda-11.1
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/your_usr_name/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/home/your_usr_name/miniconda3/etc/profile.d/conda.sh" ]; then
. "/home/your_usr_name/miniconda3/etc/profile.d/conda.sh"
else
export PATH="/home/your_usr_name/miniconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
# >>> ros noetic <<<
source /opt/ros/noetic/setup.bash
# >>> ros2 foxy <<<
# source /opt/ros/foxy/setup.bash
# >>> ur5 workspace <<<
source /home/your_usr_name/Documents/catkin_ur5/devel/setup.bash
# >>> frcobot workspace <<<
source /home/your_usr_name/Documents/catkin_frco/devel/setup.bash
# >>> pyorbbecsdk <<<
export PYTHONPATH=$PYTHONPATH:/home/your_usr_name/Documents/pyorbbecsdk/install/lib/
我将其放在.zshrc
中就修改如下
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/your_usr_name/miniconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/home/your_usr_name/miniconda3/etc/profile.d/conda.sh" ]; then
. "/home/sjhyour_usr_nameminiconda3/etc/profile.d/conda.sh"
else
export PATH="/home/your_usr_name/miniconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
# >>> clash <<<
export PATH=$PATH:/opt/clash
# >>> cuda <<<
export PATH=$PATH:/usr/local/cuda/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/cuda/lib64
# export CUDA_HOME=/usr/local/cuda-11.1
# >>> ros noetic <<<
source /opt/ros/noetic/setup.zsh
# >>> ros2 foxy <<<
# source /opt/ros/foxy/setup.zsh
# >>> ur5 workspace <<<
source /home/your_usr_name/Documents/catkin_ur5/devel/setup.zsh
# >>> frcobot workspace <<<
source /home/your_usr_name/Documents/catkin_frco/devel/setup.zsh
# >>> pyorbbecsdk <<<
export PYTHONPATH=$PYTHONPATH:/home/your_usr_name/Documents/pyorbbecsdk/install/lib/
Reference
[1]zsh 安装与配置:9步打造高效命令行