zoukankan      html  css  js  c++  java
  • Oh My Zsh 安装与配置

    切换zsh

    Manjaro linux默认安装了zsh,其他可能需要先安装

    cat /etc/shells #查看本地有哪几种shell
    chsh -s /bin/zsh #切换到zsh

    默认终端启动zsh需要在终端中进行配置

    • 打开终端,编辑>>>>首选项>>>>命令
    • 勾选“运行自定义命令而不是shell” 选项
    • 在下面的“自定义命令”中填写 "zsh"

    安装 oh-my-zsh

    ** 注意: root用户和普通用户需要单独安装配置,即分别切换到普通和root用户安装 **

    # via wget
    wget https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh && chmod 777 install.sh && ./install.sh
    
    然后执行install.sh 如果发现很慢,可以修改为gitee:
    vim install.sh
    
    REPO=${REPO:-ohmyzsh/ohmyzsh}
    REMOTE=${REMOTE:-https://github.com/${REPO}.git}
    两行改为:
    REPO=${REPO:-mirrors/oh-my-zsh}
    REMOTE=${REMOTE:-https://gitee.com/${REPO}.git}
    

    安装插件

    语法高亮插件 zsh-syntax-highlighting

    # 执行下面指令自动安装
    git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting
    
    

    自动补全插件 zsh-autosuggestions

    # 执行下面指令自动安装
    git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
    
    

    自动跳转插件 autojump

    # clone 到本地
    git clone git://github.com/joelthelion/autojump.git
    # 进入clone目录,接着执行安装文件
    cd autojump
    ./install.py
    # 接着根据安装完成后的提示,在~/.bashrc最后添加下面语句:
    vim ~/.bashrc    
    [[ -s /home/misfit/.autojump/etc/profile.d/autojump.sh ]] && source /home/misfit/.autojump/etc/profile.d/autojump.sh
    

    安装完后启用插件

    # 编辑~/.zshrc   
    vim ~/.zshrc    
    # 在plugins后括号里添加安装的插件名字
    plugins=(git autojump zsh-autosuggestions zsh-syntax-highlighting)
    # 最后刷新
    source ~/.zshrc    
    

    更改zsh主题

    选用内置主题

    主题配置文件是 ~/.zshrc , 默认是robbyrussell主题,修改选项 ZSH_THEME

    # gedit ~/.zshrc
    ZSH_THEME  = "bira"  
    "可选择的部分主题:
    agnoster
    fletcherm
    xiong-chiamiov
    gentoo
    "
    

    DIY内置主题

    以为 bira 为例,修改 ~/.oh-my-zsh/themes/bira.zsh-theme 文件,全部替换下面的配置
    主要的更改在其中DT加入了 时间戳

    # ZSH Theme - Preview: https://gyazo.com/8becc8a7ed5ab54a0262a470555c3eed.png
    local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})"
    
    local DT=`date "+%H:%M:%S"`
    if [[ $UID -eq 0 ]]; then
        local user_host='%{$terminfo[bold]$fg[red]%}%n'
        local user_symbol='#'
    else
        local user_host='%{$terminfo[bold]$fg[green]%}%n'
        local user_symbol='$'
    fi
    
    local current_dir='%{$terminfo[bold]$fg[blue]%}%~ %{$reset_color%}'
    local git_branch='$(git_prompt_info)'
    local rvm_ruby='$(ruby_prompt_info)'
    local venv_prompt='$(virtualenv_prompt_info)'
    
    ZSH_THEME_RVM_PROMPT_OPTIONS="i v g"
    
    PROMPT="╭─[${DT} %B${user_host}%b] ${current_dir}${rvm_ruby}${git_branch}${venv_prompt}
    ╰─%B${user_symbol}%b "
    RPROMPT="%B${return_code}%b"
    
    ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[yellow]%}‹"
    ZSH_THEME_GIT_PROMPT_SUFFIX="› %{$reset_color%}"
    
    ZSH_THEME_RUBY_PROMPT_PREFIX="%{$fg[red]%}‹"
    ZSH_THEME_RUBY_PROMPT_SUFFIX="› %{$reset_color%}"
    
    ZSH_THEME_VIRTUAL_ENV_PROMPT_PREFIX="%{$fg[green]%}‹"
    ZSH_THEME_VIRTUAL_ENV_PROMPT_SUFFIX="› %{$reset_color%}"
    ZSH_THEME_VIRTUALENV_PREFIX=$ZSH_THEME_VIRTUAL_ENV_PROMPT_PREFIX
    ZSH_THEME_VIRTUALENV_SUFFIX=$ZSH_THEME_VIRTUAL_ENV_PROMPT_SUFFIX
    
    

    {mtitle title="修改前"/}
    kwwaktvm.png
    {mtitle title="修改后"/}
    kwwb8p4q.png

    {callout color="#1eeb0f"}
    自动跳转插件 autojumpautojump 工作原理:它会在你每次启动命令时记录你当前位置,并把它添加进它自身的数据库中。这样,某些目录比其它一些目录添加的次数多,这些目录一般就代表你最重要的目录,而它们的“权重”也会增大。
    {/callout}

    查看版本:
    j -v
    目录跳转:
     j    [目录的名字或名字的一部分] // 不受当前所在目录的限制
    
    查看当前权重:
    j --stat
    
    进入权重最高的目录:
    j
    
    改变当前目录权重值:
    j -i [权重] // 增加
    j -d [权重] // 减少
    

    主题样式

    xiong-chiamiov主题
    {mtitle title="xiong-chiamiov主题"/}
    agnoster主题
    {mtitle title="agnoster主题"/}
    Oh-My-Zsh主题汇总

  • 相关阅读:
    coredump分析
    Sword LRU算法
    C++ STL迭代器失效问题
    Sword DB主从一致性的解决方法
    Sword CRC算法原理
    C语言 按位异或实现加法
    Linux 等待信号(sigsuspend)
    C语言 宏定义之可变参数
    Linux shell字符串操作
    C++ *和&
  • 原文地址:https://www.cnblogs.com/misfit/p/15659565.html
Copyright © 2011-2022 走看看