Mac 上快速安装 oh-my-zsh

06-01 1552阅读

Mac 上快速安装 oh-my-zsh

  1. 检测mac自带的zsh
    $ cat /etc/shells
    # List of acceptable shells for chpass(1).
    # Ftpd will not allow users to connect who are not using
    # one of these shells.
    /bin/bash
    /bin/csh
    /bin/dash
    /bin/ksh
    /bin/sh
    /bin/tcsh
    /bin/zsh
    
  2. 设置zsh

    查看zsh版本

    $ zsh --version
    zsh 5.8.1 (x86_64-apple-darwin21.0)
    

    把zsh设置成默认shell

    # 查看
    $ echo $(which zsh)
    /bin/zsh
    # 设置
    $ chsh -s $(which zsh)
    # 查检-需要关闭终端重新打开后生效
    $ echo $SHELL
    /bin/zsh
    
  3. 安装

    • 下载仓库

      git clone https://github.com/ohmyzsh/ohmyzsh.git ~/.oh-my-zsh
      
    • 在.zshrc文件中复制我们为您包含的模板

      cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
      
    • 更改默认shell的配置,然后重启终端

      chsh -s $(which zsh)
      
    • 修改主题

      主题列表:https://github.com/ohmyzsh/wiki/blob/main/Themes.md

​ 打开设置:~/.zshrc

# Set name of the theme to load --- if set to "random", it will
# load a random theme each time Oh My Zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="crcandy"

​ 修改主题为 crcandy,并重启终端生效。

  1. 安装**zsh-completions** 插件
    • 在 oh-my-zsh repo 中克隆存储库:

      git clone https://github.com/zsh-users/zsh-completions ${ZSH_CUSTOM:-${ZSH:-~/.oh-my-zsh}/custom}/plugins/zsh-completions		
      
    • 增加 FPATH 在 .zshrc 文件中,增加在 source "$ZSH/oh-my-zsh.sh" 之前:

      fpath+=${ZSH_CUSTOM:-${ZSH:-~/.oh-my-zsh}/custom}/plugins/zsh-completions/src
      
    • 验证

      > % git cl
      clean -- remove untracked files from working tree
      clone -- clone repository into new directory
      
    • 插件推荐
      • zsh-syntax-highlighting

        这款插件可以实时检测命令是否出错。

        下载插件到指定目录,使用如下命令即可:

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

        然后修改配置文件.zshrc,在plugins中添加插件zsh-syntax-highlighting;

        Mac 上快速安装 oh-my-zsh
        (图片来源网络,侵删)
        plugins=(
                git
                zsh-syntax-highlighting
        )
        
      • zsh-autosuggestions

        自动补全插件,输入命令后会自动提示相关命令,使用方向键→可以实现自动补全。

        git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
        
      • zsh-history-substring-search

        可以搜索命令历史的插件,使用Ctrl+R快捷键触发,模糊搜索历时使用的命令。

        Mac 上快速安装 oh-my-zsh
        (图片来源网络,侵删)
        git clone https://github.com/zsh-users/zsh-history-substring-search ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-history-substring-search
        
Mac 上快速安装 oh-my-zsh
(图片来源网络,侵删)
免责声明:我们致力于保护作者版权,注重分享,被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理! 图片声明:本站部分配图来自人工智能系统AI生成,觅知网授权图片,PxHere摄影无版权图库和百度,360,搜狗等多加搜索引擎自动关键词搜索配图,如有侵权的图片,请第一时间联系我们。

目录[+]

取消
微信二维码
微信二维码
支付宝二维码