Mac下 ITerm2 + Oh-My-Zsh 安裝使用
Mac系統(tǒng)下雖然有【終端terminal】,但更推薦使用【iTerm2 + oh-my-zsh】。
Shell
在操作系統(tǒng)內(nèi)核外有一層殼,而這層殼就是 shell,它是用戶和操作系統(tǒng)交互的橋梁。
shell 包住了系統(tǒng),用戶想要跟系統(tǒng)交互,就必須經(jīng)過(guò)shell。
shell 接收用戶或其他程序的命令,把這些命令轉(zhuǎn)化成內(nèi)核能理解的語(yǔ)言。
我們常見(jiàn)的 shell 有:bash、zsh、csh、ksh、ash 等。
相較于bash,zsh有著許多優(yōu)點(diǎn):
- 更豐富的命令提示
- 更鮮明的演示標(biāo)記
- 更強(qiáng)大的插件支持
Linux 下默認(rèn)的是 bash ,macOS 在 Catalina 之前的版本默認(rèn)也是 bash ,后面隨著 zsh 越來(lái)越流行,macOS 開(kāi)始將 zsh 作為默認(rèn)的解釋器了。
可以使用命令 chsh 更換登錄系統(tǒng)時(shí)使用的shell。
# 查看系統(tǒng)中的shells
cat /etc/shells
# 使用zsh
chsh -s /bin/zsh
# 使用bash
chsh -s /bin/bash
oh-my-zsh 簡(jiǎn)介
默認(rèn)的 zsh 配置有點(diǎn)煩;oh-my-zsh 可以簡(jiǎn)化 zsh 配置。
oh-my-zsh的 github 地址:GitHub - ohmyzsh/ohmyzsh: A delightful community-driven (with 2,200+ contributors) framework for managing your zsh configuration. Includes 300+ optional plugins (rails, git, macOS, hub, docker, homebrew, node, php, python, etc), 140+ themes to spice up your morning, and an auto-update tool so that makes it easy to keep up with the latest updates from the community。
zsh 對(duì)應(yīng)的配置文件:~/.zshrc
oh-my-zsh 安裝
- 打開(kāi)官網(wǎng):Oh My Zsh - a delightful & open source framework for Zsh
- 點(diǎn)擊【Install oh-my-zsh】按鈕
Install oh-my-zsh
- 提供了 curl 和 wget 兩種安裝方式,選擇其中之一即可
# curl
sh -c "$(curl -fsSL <https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh>)"
# wget
sh -c "$(wget <https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh> -O -)"
修改主題
可以在 Github 上查看都有哪些主題風(fēng)格:Themes · ohmyzsh/ohmyzsh Wiki · GitHub。
配置文件中的 ZSH_THEME 字段配置的就是當(dāng)前的主題
本地已有的主題都存放在 ~/.oh-my-zsh/themes 目錄中
ls ~/.oh-my-zsh/themes
如果要使用第三方主題,下載并保存到~/.oh-my-zsh/custom/themes 目錄中,并設(shè)置主題字段
# 下載第三方主題
git clone <https://github.com/bhilburn/powerlevel9k.git> ~/.oh-my-zsh/custom/themes/powerlevel9k
# 編輯配置文件,配置 ZSH_THEME 字段
vim ~/.zshrc
# source 一下,使之生效
source ~/.zshrc
添加插件
在Github上面查看有哪些可用的插件:Plugins · ohmyzsh/ohmyzsh Wiki · GitHub。
我們下載的插件一般存放到~/.oh-my-zsh/custom/plugins 目錄中。
配置文件中的 plugins 字段配置的就是插件
zsh推薦插件:
zsh-autosuggestions 命令補(bǔ)全
zsh-syntax-highlighting 語(yǔ)法高亮
git
具體步驟如下:
# 切換到插件目錄
cd ~/.oh-my-zsh/custom/plugins/
# 下載插件到當(dāng)前目錄
git clone <https://github.com/zsh-users/zsh-autosuggestions>
# 編輯配置文件,配置 plugins 字段
vi ~/.zshrc
# source 一下,使之生效
source ~/.zshrc