Linux Shell美化:oh-my-zsh

  1. 查看当前shell

    echo $SHELL
    /bin/bash
    
  2. 查看当前是否安装zsh

    cat /etc/shells 
    
    /bin/sh
    /bin/bash
    /usr/bin/sh
    /usr/bin/bash
    /bin/tcsh
    /bin/csh
    
  3. 安装zsh

    yum install -y zsh
    
  4. 设置默认shell

    chsh -s /bin/zsh
    
  5. 安装oh-my-zsh 需要git

    # 如果没有git,则安装
    yum install -y git
    sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
    
  6. 安装插件

    • zsh-autosuggestions

      官网。非常好用的一个插件,会记录你之前输入过的所有命令,并且自动匹配你可能想要输入命令,然后按→补全

      # 1. Clone this repository in oh-my-zsh's plugins directory:
      git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
      
      # 2. Activate the plugin in ~/.zshrc:
      plugins=( [plugins...] zsh-autosuggestions)
      
    • zsh-syntax-highlighting

      官网。命令太多,有时候记不住,等输入完了才知道命令输错了,这个插件直接在输入过程中就会提示你,当前命令是否正确,错误红色,正确绿色

      # 1. Clone this repository into $ZSH_CUSTOM/plugins
      git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
      
      
      # 2. Add the plugin to the list of plugins for Oh My Zsh to load (inside ~/.zshrc):
      plugins=( 
          # other plugins...
           zsh-syntax-highlighting
      )
      
    • sudo

      偶尔输入某个命令,提示没有权限,需要加sudo,这个时候按两下ESC,就会在命令行头部加上sudo

  7. 修改主题

    • .oh-my-zsh/themes目录下新建一个主题my.zsh-theme,添加下面内容:
     PROMPT="
    %{$fg[cyan]%}%M(%{$fg[red]%}%n) %(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )"
    PROMPT+='%{$fg[cyan]%}%c%{$reset_color%}:'
    RPROMPT="%{$fg[blue]%}%T $(git_prompt_info)"
    
    ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[blue]%}git:(%{$fg[red]%}"
    ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
    ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}✗"
    ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})"
    

    这个是根据自带的主题简单修改的,关于怎么自己写自定义主题,参考我写的另一篇文章

    • 修改.zshrc文件,修改主题配置字段:ZSH_THEME="my"

    • 最后source .zshrc

References:

  1. CentOS 安装 zsh

  2. oh-my-zsh常用插件

你可能感兴趣的:(Linux Shell美化:oh-my-zsh)