查看是否安装
cat /etc/shells
# /etc/shells: valid login shells
/bin/sh
/bin/bash
/usr/bin/bash
/bin/rbash
/usr/bin/rbash
/bin/dash
/usr/bin/dash
/bin/zsh # 有这个说明已经安装了
/usr/bin/zsh
/usr/bin/tmux
查看当前shell 类型
echo $SHELL
安装
# 安葬
sudo apt install zsh
# 默认shell 设置zsh
chsh -s /bin/zsh
# 配置密码文件,解决chsh: PAM认证失败的问题; 第一行最后面是zsh
root:x:0:0:root:/root:/bin/zsh
# 网友提供的安装配置oh-my-zsh脚本
sh -c "$(curl -fsSL https://gitee.com/shmhlsy/oh-my-zsh-install.sh/raw/master/install.sh)"
# oh-my-zsh 路径为 ~/.oh-my-zsh/
# oh-my-zsh 核心脚本 ~/.oh-my-zsh/oh-my-zsh.sh
# .zshrc 里面也会执行 上面的脚本
# 安装好用的插件
# 自动补全, 不设置设个,补全效果不好
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh}/plugins/zsh-autosuggestions
# 语法高亮
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh}/plugins/zsh-syntax-highlighting
# 快捷跳转
sudo apt-get install autojump
配置.zshrc
# 加载插件
plugins=(git zsh-autosuggestions zsh-syntax-highlighting)
# 启动autojump
source /usr/share/autojump/autojump.sh
# rosenv
ros2init(){
source /opt/ros/rolling/setup.zsh
export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp
export ROS_DOMAIN_ID=42
export ROS_VERSION=2
export ROS_PYTHON_VERSION=3
export ROS_DISTRO=rolling
}
卸载zsh
sudo sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/uninstall.sh)"
把/etc/passwd改回bash, 注意第一行,和最后一行
root:x:0:0:root:/root:/bin/zsh
hopps:x:1000:1000:hopps,,,:/home/hopps:/usr/bin/zsh
如何修改zsh 终端的输出格式
首先知道linux PS1 prompt
zsh 好像与这两个关系不大,应为格式输出与主题关系大,应该在主题脚本里查看
设置ros/ros2 开发环境变量,在.zshrc 后面添加
r2() {
export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp
export ROS_VERSION=2
export ROS_PYTHON_VERSION=3
export ROS_DISTRO=galactic
#export ROS_DOMAIN_ID=42
source /opt/ros/galactic/setup.zsh
source /usr/share/colcon_argcomplete/hook/colcon-argcomplete.zsh
source /usr/share/colcon_cd/function/colcon_cd.sh
eval "$(register-python-argcomplete3 ros2)"
eval "$(register-python-argcomplete3 colcon)"
}
r1() {
source /opt/ros/noetic/setup.zsh
export ROS_VERSION=1
#export ROS_MASTER_URI=3
#export ROS_IP=
export ROS_DISTRO=noetic
}
#r1
#r2