Oh My Zsh初体验

macOS升级到Catalina(10.15)后,终端默认的shell变成了zsh,结果发现之前配置的Git命令自动补齐功能无法使用,在搜寻其他替代解决方案时发现了Oh My Zsh,本文主要记录一下Oh My Zsh的简单使用,大神忽略。

bash是目前大多数Linux系统默认使用的shell,全名BourneAgain Shell,一共有40个命令。包含的功能几乎可以涵盖shell所具有的功能,所以一般的shell脚本都会指定它为执行路径。

从 macOS Catalina Beta 版开始,zsh (Z shell) 成为macOS下所有新建用户的默认 Shell。

我们可以通过下面命令,来查看当前系统支持的所有shell

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

Oh My Zsh是一个开源的、社区驱动用于管理zsh配置的框架。

安装

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

安装完之后,会在你的用户目录下新建两个文件:.oh-my-zsh .zshrc。.oh-my-zsh目录就是Oh-My-Zsh的项目Git克隆目录,.zshrc则是Oh-My-Zsh帮你生成的zsh配置文件。

.zshrc

主题设置

在.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/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="robbyrussell"

这里可以设置主题的名字,我们可以通过如下命令来查看Oh-My-Zsh已经存在的主题配置

ls .oh-my-zsh/themes

3den.zsh-theme                 darkblood.zsh-theme            gallois.zsh-theme              kennethreitz.zsh-theme         norm.zsh-theme                 strug.zsh-theme
Soliah.zsh-theme               daveverwer.zsh-theme           garyblessington.zsh-theme      kiwi.zsh-theme                 obraun.zsh-theme               sunaku.zsh-theme
adben.zsh-theme                dieter.zsh-theme               gentoo.zsh-theme               kolo.zsh-theme                 peepcode.zsh-theme             sunrise.zsh-theme
af-magic.zsh-theme             dogenpunk.zsh-theme            geoffgarside.zsh-theme         kphoen.zsh-theme               philips.zsh-theme              superjarin.zsh-theme
afowler.zsh-theme              dpoggi.zsh-theme               gianu.zsh-theme                lambda.zsh-theme               pmcgee.zsh-theme               suvash.zsh-theme
agnoster.zsh-theme             dst.zsh-theme                  gnzh.zsh-theme                 linuxonly.zsh-theme            pygmalion-virtualenv.zsh-theme takashiyoshida.zsh-theme
alanpeabody.zsh-theme          dstufft.zsh-theme              gozilla.zsh-theme              lukerandall.zsh-theme          pygmalion.zsh-theme            terminalparty.zsh-theme
amuse.zsh-theme                duellj.zsh-theme               half-life.zsh-theme            macovsky-ruby.zsh-theme        re5et.zsh-theme                theunraveler.zsh-theme
apple.zsh-theme                eastwood.zsh-theme             humza.zsh-theme                macovsky.zsh-theme             refined.zsh-theme              tjkirch.zsh-theme
arrow.zsh-theme                edvardm.zsh-theme              imajes.zsh-theme               maran.zsh-theme                rgm.zsh-theme                  tjkirch_mod.zsh-theme
aussiegeek.zsh-theme           emotty.zsh-theme               intheloop.zsh-theme            mgutz.zsh-theme                risto.zsh-theme                tonotdo.zsh-theme
avit.zsh-theme                 essembeh.zsh-theme             itchy.zsh-theme                mh.zsh-theme                   rixius.zsh-theme               trapd00r.zsh-theme
awesomepanda.zsh-theme         evan.zsh-theme                 jaischeema.zsh-theme           michelebologna.zsh-theme       rkj-repos.zsh-theme            wedisagree.zsh-theme
bira.zsh-theme                 fino-time.zsh-theme            jbergantine.zsh-theme          mikeh.zsh-theme                rkj.zsh-theme                  wezm+.zsh-theme
blinks.zsh-theme               fino.zsh-theme                 jispwoso.zsh-theme             miloshadzic.zsh-theme          robbyrussell.zsh-theme         wezm.zsh-theme
bureau.zsh-theme               fishy.zsh-theme                jnrowe.zsh-theme               minimal.zsh-theme              sammy.zsh-theme                wuffers.zsh-theme
candy-kingdom.zsh-theme        flazz.zsh-theme                jonathan.zsh-theme             mira.zsh-theme                 simonoff.zsh-theme             xiong-chiamiov-plus.zsh-theme
candy.zsh-theme                fletcherm.zsh-theme            josh.zsh-theme                 mortalscumbag.zsh-theme        simple.zsh-theme               xiong-chiamiov.zsh-theme
clean.zsh-theme                fox.zsh-theme                  jreese.zsh-theme               mrtazz.zsh-theme               skaro.zsh-theme                ys.zsh-theme
cloud.zsh-theme                frisk.zsh-theme                jtriley.zsh-theme              murilasso.zsh-theme            smt.zsh-theme                  zhann.zsh-theme
crcandy.zsh-theme              frontcube.zsh-theme            juanghurtado.zsh-theme         muse.zsh-theme                 sonicradish.zsh-theme
crunch.zsh-theme               funky.zsh-theme                junkfood.zsh-theme             nanotech.zsh-theme             sorin.zsh-theme
cypher.zsh-theme               fwalch.zsh-theme               kafeitu.zsh-theme              nebirhos.zsh-theme             sporty_256.zsh-theme
dallas.zsh-theme               gallifrey.zsh-theme            kardan.zsh-theme               nicoulaj.zsh-theme             steeef.zsh-theme

需要注意的是,在使用某些主题时(比如agnoster),需要安装Powerline Fonts,否则会导致终端的命令行出现?这样的符号。

插件

Oh My Zsh的.oh-my-zsh/plugins目录下存放了很多默认自带的插件,打开.zshrc配置文件,定位到plugins:

# Which plugins would you like to load?
# Standard plugins can be found in ~/.oh-my-zsh/plugins/*
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git)

可以看到默认只开启了git插件,如果要启用其他插件,则将要使用的插件的名字以空格相隔接在后面就可以了,比如:

plugins=(git adb)

参考

在 Mac 上将 zsh 用作默认 Shell

这篇文章目前没有评论。

回复

(必填项)

(必填项)

(可选)