zsh和oh-my-zsh

背景

默认terminal为 /bin/bash
有如下问题:

  • 在使用git时无法体现当前brach
  • 大小写需要手动切换

于是动手安装下oh-my-zsh。
** 同时建议安装tmux+zsh **

安装

oh-my-zsh 需要安装zsh

安装zsh

  • cat /etc/issue
  • sudo apt-get install zsh -y安装zsh
  • zsh --version确认是否安装成功
  • chsh -l or which zsh chsh -s /usr/bin/zsh 设置zsh为默认shell
    注销重新登录,再打开terminal如图:
    image.png
  • echo $SHELL确认zsh是否是默认SHELL,如果是则会输出/usr/bin/zsh。如果有问题可以sudo vim /etc/passwd将root和当前用户的/bin/bash改为/usr/bin/zsh
    或者没有权限就在.profile .bashrc中加入
if [ -t 1 ]; then
    exec zsh
fi

安装oh-my-zsh

安装

sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

修改配置

Oh-My-Zsh的默认配置文件在:~/.zshrc
编辑~/.zshrc修改主题为:
ZSH_THEME="agnoster"

此时重启terminal会发现乱码,这是因为缺少相应字体。

安装字体

sudo apt-get install fonts-powerline

完成。

其他

插件推荐

oh-my-zsh 插件推荐

命令高亮

# macOS
brew install zsh-syntax-highlighting
#  linux
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

目录自动跳转

# macOS
brew install autojump
# linux
git clone git://github.com/joelthelion/autojump.git && cd autojump && python3 install.py && cd .. && rm -rf autojump

配置

# 使用brew安装的
[[ -s $(brew --prefix)/etc/profile.d/autojump.sh ]] && . $(brew --prefix)/etc/profile.d/autojump.sh
source $ZSH/oh-my-zsh.sh
# 使用git安装的
[[ -s ~/.autojump/etc/profile.d/autojump.sh ]] && . ~/.autojump/etc/profile.d/autojump.sh
autoload -U compinit && compinit -u

zsh-autosuggestion

# macos
brew install zsh-autosuggestions
# linux
git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions

更新

vim ~/.zshrc
plugins=(
        git
        autojump
        zsh-autosuggestions
        zsh-syntax-highlighting
        docker 
        docker-compose
)
source ~/.zshrc

.bashrc

如果是zsh则plugins=()添加即可,如果没用zsh,则在.bashrc加入配置

echo "source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ~/.bashrc
# vim .zshrc
[[ -s /home/gbxu/.autojump/etc/profile.d/autojump.sh ]] && source /home/gbxu/.autojump/etc/profile.d/autojump.sh
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容