zsh是一个shell环境,不过和一般使用的bash shell不同,zsh的交互性更强也更人性化。(bash还有一些莫名其妙的bug)
下面介绍一下怎么在Ubuntu中安装和使用zsh。
安装
sudo apt-get update
sudo apt-get install zsh
# 下面是把系统默认的shell换成zsh, 重启后生效
command -v zsh | sudo tee -a /etc/shells
chsh -s `which zsh`
安装 on-my-zsh,这个是zsh的一个插件库,包含各种常用的插件和主题。详情可以看这里
wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | zsh
环境变量的的设置
在bash 中一般会有很多环境变量,如果这些变量没有在zsh中设置的话就会导致各种程序的错误。
一般bash的环境变量在.bashrc中
source /opt/ros/kinetic/setup.bash
export PATH=/home/randoms/Programs/android-sdk-linux/platform-tools:$PATH
export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/.go
export PATH=$GOPATH/bin:$PATH
source /home/randoms/Documents/ros/workspace/devel/setup.sh
export ROS_PACKAGE_PATH=/home/randoms/Documents/ros/workspace/src:/home/randoms/Documents/ros/workspace/src/ORB_SLAM2/Examples/ROS:$ROS_PACKAGE_PATH
export BUP_DIR=/home/randoms/backup/bup
ulimit -c unlimited
比如这是我的一些的环境变量的设置
基本上直接复制到.zshrc文件里面就可以了。需要注意的是source
指令。zsh中没办法source bash的文件。
source xxx.sh
# 更改为,这实际上是开了一个sh的模拟器去解释执行bash指令
emulate sh -c 'source xxx.sh'
对应上面的内容更改为
emulate sh -c 'source /opt/ros/kinetic/setup.sh'
export PATH=/home/randoms/Programs/android-sdk-linux/platform-tools:$PATH
export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/.go
export PATH=$GOPATH/bin:/home/randoms/Documents/SharpLink/SharpLink/bin/Debug:$PATH
emulate sh -c 'source /home/randoms/Documents/ros/workspace/devel/setup.sh'
export ROS_PACKAGE_PATH=/home/randoms/Documents/ros/workspace/src:/home/randoms/Documents/ros/workspace/src/ORB_SLAM2/Examples/ROS:$ROS_PACKAGE_PATH
export BUP_DIR=/home/randoms/backup/bup
ulimit -c unlimited
这样就可以了。
下面来一个zsh的截图
Updata:
对于ROS的source脚本并不能完全这样设置。这样设置后有些指令不能使用。发现ROS默认是提供了setup.zsh的脚本的
所以上面的配置可以变成这样
. /opt/ros/kinetic/setup.zsh
export PATH=/home/randoms/Programs/android-sdk-linux/platform-tools:$PATH
export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/.go
export PATH=$GOPATH/bin:/home/randoms/Documents/SharpLink/SharpLink/bin/Debug:$PATH
#emulate sh -c 'source /home/randoms/Documents/ros/workspace/devel/setup.sh'
. /home/randoms/Documents/ros/workspace/devel/setup.zsh
export ROS_PACKAGE_PATH=/home/randoms/Documents/ros/workspace/src:/home/randoms/Documents/ros/workspace/src/ORB_SLAM2/Examples/ROS:$ROS_PACKAGE_PATH
export BUP_DIR=/home/randoms/backup/bup
ulimit -c unlimited
这样就一切正常了。