安装 oh my zsh

Zsh 安装与配置

shell 是一款可用作交互式登录的 shell 及脚本编写的命令解释器,Zsh 对 Bourne shell 做出了大量改进,同时加入了 Bash、ksh 及 tcsh 的某些功能。(维基百科)

安装 zsh

sudo apt install zsh

设置为默认shell

sudo chsh -s `which zsh`

安装 oh my zsh

  • git安装
    sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
    
  • 如果报错使用国内源
    git clone https://mirrors.tuna.tsinghua.edu.cn/git/ohmyzsh.git && cd ohmyzsh/tools && REMOTE=https://mirrors.tuna.tsinghua.edu.cn/git/ohmyzsh.git sh install.sh
    确保可以正常访问github,否则打开终端时omz的自动更新可能会卡住

安装插件

  1. 命令补全
    git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
    
  • 如果有问题用国内源:
    git clone https://gitee.com/hailin_cool/zsh-autosuggestions.git $ZSH_CUSTOM/plugins/zsh-autosuggestions
    
  1. 语法高亮

    git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
    
  2. 激活插件:

    ~/.zshrc文件找到plugins=(git docker docker-compose zsh-syntax-highlighting zsh-autosuggestions),在其中添加zsh-syntax-highlighting,重启终端

自动跳转

  • 有时需要进入一个比较深的目录,比如/home/user/mail/inbox,cd进去是比较麻烦的

  • autojump插件可以记录访问过的目录,只需输入 j 关键词 回车,就能跳转到以前访问过的包含该关键词的目录

  • 如果安装了图形界面,还可以用jo 关键词,在文件管理器中打开

  • 手动安装

    git clone git://github.com/wting/autojump.git
    
    
    cd autojump
    
    ./install.py
    
  • 然后根据输出的内容编辑~/.zshrc

包管理器安装

  • Debian系安装autojump,RedHat系安装autojump-zsh

  • Debian系还要根据/usr/share/doc/autojump/README.Debian的内容配置~/.zshrc

  • 完成后开启新终端,使用autojump -h验证是否生效

字体

  • oh-my-zsh配置中采用的是Powerline字体,而本人本地windows中不包含该系列字体,因此才会出现乱码的问题。知道原因后那么就很好解决该问题了。 直接在windows中安装powerline字体并在vscode中进行设置!

  • 解决步骤
    下载powerline字体
    下载链接:https://github.com/powerline/fonts

  • 安装字体
    windows中安装字体直接打开对应的字体文件夹右键进行安装!(PS:安装一种powerline字体即可)
    vscode中设置终端
    在setting中搜索terminal选项,然后修改字体为powerline字体即可。例如本人采用的是Space Mono For Powerline:

  • 修改完成后字体显示正常啦!果然是好看多了!!!

  • 最后的配置文件:

    export ZSH="$HOME/.oh-my-zsh"
    
    ZSH_THEME="powerlevel10k/powerlevel10k"
    
    plugins=(git docker docker-compose zsh-syntax-highlighting zsh-autosuggestions)
    source $ZSH/oh-my-zsh.sh
    
    source ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
    POWERLEVEL9K_DISABLE_CONFIGURATION_WIZARD=true
    
    

解决无法自动更新的问题

有三种解决方式:

  1. 关闭自动更新

    在 ~/.zshrc中取消注释这一行:

     zstyle ':omz:update' mode disabled
    
  2. 修改更新地址

    cd ~/.oh-my-zsh

    git remote set-url origin https://gitee.com/mirrors/oh-my-zsh.git

  3. 为git配置代理

    git config --global http.proxy ‘socks5://{ip}:{port}’

    git config --global https.proxy ‘socks5://{ip}:{port}’

配置主题

  • ~/.on-my-zsh/themes下存放着许多主题文件,可以通过修改~/.zshrc里的ZSH_THEME=""来设置

  • 如果设置为random,每次打开终端都会使用随机的主题

  1. robbyrussell
    image.png

  2. agnoster
    image.png

  3. Powerlevel10k 主题 需要另行安装
    image.png

  • 需要使用 MesloLGS NF 字体

  • 安装主题Powerlevel10k

    git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
    
  • ~/.zshrc中设置ZSH_THEME="powerlevel10k/powerlevel10k"

  • 执行以下命令将 Powerlevel10k 添加到配置文件中:

    echo 'source ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k ' >>~/.zshrc 
    
  • 使用主题
    vi ~/.zshrc 修改ZSH_THEME为ZSH_THEME=“powerlevel10k”

  • 使配置文件生效:

    source ~/.zshrc
    

链接: https://dreamhomes.github.io/posts/202006222027/

参考https://www.debugpoint.com/oh-my-zsh-powerlevel10k/

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值