工具相关

用「zsh」「oh my zsh」「powerlevel10k」

2019-05-10  本文已影响0人  大木头啊啊

1. 前言

对于管理人员和开发人员来说,一个好的终端可以给你带来效率飞速的提升。

你还在用这样的 bash 吗?


image-20190510144143335.png

或着用这样的 终端?


image-20190510144943033.png

是时候打造一款属于你自己的终端配置啦!让它兼具美观好看和高效。

今天要介绍的终端美化方案是「zsh」+「oh my zsh」+「powerlevel10k」。你或许在百度上看到过 zsh+oh-my-zsh+powerlevel9k 的终端环境美化方案,它和我的美化方案没什么大不同,只不过将 powerlevel9k 换成了powerlevel10k, 它是 9k 版本的强化版本,更快,性能更好。

接下去将一步步介绍安装部署步骤。

2. 安装 zsh

Linux 环境下的 shell 终端并不知有 bash,常见的还有 ksh,tcsh,zsh,fish等。其中大部分人用的是 bash,估计是因为大部分的 Linux 发行版默认的就是 bash 的缘故。我们来看一下各终端的使用占比


image-20190510150748950.png

数据来源于:https://opensource.com/business/16/3/top-linux-shells

有些平台默认就有 zsh 终端,只是默认不启用,下面简单介绍各环境下把 zsh 切换成默认的 shell 环境。

3. 安装 oh my zsh

68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6f686d797a73682f6f682d6d792d7a73682d6c6f676f2e706e67.png

官网是这样介绍 oh my zsh 的,然后详细的文档可以去 github 网址:https://github.com/robbyrussell/oh-my-zsh

Oh My Zsh is a delightful, open source, community-driven framework for managing your Zsh configuration. It comes bundled with thousands of helpful functions, helpers, plugins, themes, and a few things that make you shout...

Oh My Zsh可以做非常多的定制化功能,比如主题,字体,插件等。

简单介绍如何安装 oh my zsh

4. 安装 powerlevel10k

4.1 为什么选择powerlevel10k?

Oh My Zsh有上百个自带主题,以及许许多多的外部主题。目前来看使用量教多的是 powerlevel9k,它的初始效果是这样的。

687474703a2f2f692e696d6775722e636f6d2f777942565a51792e676966.gif

这个主题我也用了挺长一段时间,用上它的感觉就是「妈的,虽然好用,但是响应速度让我很不爽,明明没有加载很多插件还是慢」。这个感觉直到我逛主题市场发现 powerlevel10k 后就再也不复存在了。

它的介绍是这样的,注意关键字:兼容 Powerlevel9k,10-100倍的性能提升!

Powerlevel10k is a backward-compatible reimplementation of the popular Powerlevel9k theme (see above) with 10-100 times better performance. If you like the looks of Powerlevel9k but feeling frustrated by its slow prompt, simply replace your powerlevel9k theme with powerlevel10k and enjoy responsive shell like it's 80's again! Powerlevel10k uses the same configuration options as Powerlevel9k and produces the same results. It's simply faster.

简单介绍如何安装 powerlevel10k,详细的教程自己去看:https://github.com/romkatv/powerlevel10k

5. 安装字体

安装完 powerlevel10k 后你可能会发现有乱码,这是因为你终端字体不支持那么多的字符,这就需要使用扩展字体了。

字体的安装,我们可以参考 powerlevel9k 的官方介绍:https://github.com/bhilburn/powerlevel9k/wiki/Install-Instructions#step-2-install-a-powerline-font

安装 powerline 字体有四种方式:

Option 1: Install Powerline Fonts

不介绍,请看官方文档

Option 2: Use a Programmer Font

不介绍,请看官方文档

Option 3: Install Awesome-Powerline Fonts

不介绍,请看官方文档

Option 4: Install Nerd-Fonts

Nerd 字体应该是支持字形最多的,所以不用多想,安装它就好了!

github 上也有详细的安装介绍文档:https://github.com/ryanoasis/nerd-fonts#font-installation

其中最简单的应该是用 Homebrew,但是Homebrew在国内的访问速度实在恶心,所以还是选择手工安装吧

直接上 nerdfonts 官网,找到Downloads,直接下载 Hack 字体,别问我为什么,如果是mac,直接双击安装下载的字体即可,然后修改 oh my zsh 的变量文件 ~/.zshrc,修改变量 POWERLEVEL9K_MODE='nerdfont-complete', 如果不是MacOS,先自行查找如何配置 powerline 字体吧。

image-20190510160619735.png

6. 常用插件

环境配置好了,我们还需要加上一些插件让终端更好用,介绍我用的几个插件,效率杠杠的

7. 完整zshrc配置

实际效果


image-20190510164844255.png

.zshrc文件配置

# Prompts
POWERLEVEL9K_LEFT_SEGMENT_SEPARATOR='\uE0C0'
#POWERLEVEL9K_LEFT_SUBSEGMENT_SEPARATOR='\uE0C0'
POWERLEVEL9K_RIGHT_SEGMENT_SEPARATOR='\uE0C2'
#POWERLEVEL9K_RIGHT_SUBSEGMENT_SEPARATOR='\uE0C2'
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(dir dir_writable vcs virtualenv)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status background_jobs command_execution_time ip)
POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
POWERLEVEL9K_SHORTEN_DELIMITER=..
POWERLEVEL9K_PROMPT_ON_NEWLINE=true
POWERLEVEL9K_MULTILINE_FIRST_PROMPT_PREFIX=$'\n'
POWERLEVEL9K_MULTILINE_LAST_PROMPT_PREFIX="\uF460%F{073}\uF460%F{109}\uF460%f "
export ZSH="/Users/john/.oh-my-zsh"
POWERLEVEL9K_MODE='nerdfont-complete'
ZSH_THEME="powerlevel10k/powerlevel10k"
export UPDATE_ZSH_DAYS=13
HIST_STAMPS="yyyy/mm/dd"
plugins=(
    git
    colored-man-pages
    colorize
    github
    brew
    osx
    docker
    docker-compose
    autojump
    zsh-autosuggestions
    zsh-syntax-highlighting
    autopep8
    python
)
source $ZSH/oh-my-zsh.sh
alias zshconfig="vim ~/.zshrc"
alias vimconfig="vim ~/.vimrc"
alias ansibleconfig="vim ~/.ansible/ansible.cfg"
alias grep='grep --color=auto'
上一篇下一篇

猜你喜欢

热点阅读