Mac配置炫酷終端以及直接預覽Markdown和各類代碼

1. 下載iTerm2

 

brew cast install iTerm2

安裝完成後,在/bin目錄下會多出一個zsh的文件。

Mac系統默認使用dash作爲終端,可以使用命令修改默認使用zsh:

chsh -s /bin/zsh

zsh完美代替bash,具體區別可查看:《Zsh和Bash區別》

iterm2的原始界面

2. 替換背景圖片

打開路徑:iterm2 -> Preferences -> Profiles -> window -> Background Image

選擇一張自己喜歡的壁紙即可

可以通過Blending調節壁紙的透明度: 透明度爲0的時候,背景變爲純色(黑色)

我個人比較喜歡扁平化的壁紙,喜歡的朋友可以來這裏看看:
《有哪些優雅的 Windows 10 壁紙?》

3. 安裝Oh my zsh

zsh的功能極其強大,只是配置過於複雜,通過Oh my zsh可以很快配置zsh。

這裏只做簡單的配置,如需要深入瞭解,可以查看:《oh-my-zsh,讓你的終端從未這麼爽過》

安裝方法有兩種,可以使用curl或wget,看自己環境或喜好:

# curl 安裝方式
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
# wget 安裝方式
sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"

oh-my-zsh開源地址:《oh-my-zsh》

4. 安裝PowerLine

首先先安裝pip命令:

sudo easy_install pip

pip是python的一個維護命令

安裝powerline:

pip install powerline-status --user

5. 安裝PowerFonts

在常用的位置新建一個文件夾,如:~/Desktop/OpenSource/

OpenSource文件夾下下載PorweFonts:

# git clone
git clone https://github.com/powerline/fonts.git --depth=1

# cd to folder
cd fonts

# run install shell
./install.sh

執行結果如下:

安裝好字體庫之後,我們來設置iTerm2的字體,具體的操作是:

iTerm2 -> Preferences -> Profiles -> Text

在Font區域選中Change Font,然後找到Meslo LG字體。

6. 安裝配色方案(可跳過)

在OpenSource目錄下執行git clone命令:

git clone https://github.com/altercation/solarized

cd solarized/iterm2-colors-solarized/
open .

在打開的finder窗口中,雙擊Solarized Dark.itermcolors和Solarized Light.itermcolors即可安裝明暗兩種配色:

再次進入iTerm2 -> Preferences -> Profiles -> Colors -> Color Presets中根據個人喜好選擇.

7. 安裝主題

在OpenSource目錄下執行git clone命令:

git clone https://github.com/fcamblor/oh-my-zsh-agnoster-fcamblor.git

cd oh-my-zsh-agnoster-fcamblor/
./install

執行上面的命令會將主題拷貝到oh my zsh的themes.

執行命令打開zshrc配置文件,將ZSH_THEME後面的字段改爲agnoster

vi ~/.zshrc

我這裏簡單說一下vim的一些操作命令,不熟悉的可以看看:

鍵盤i: 進入可編輯模式,最下面顯示-- INSERT --

鍵盤esc: 退出編輯模式

shift + : : 執行命令操作

輸入wq: 保存當前更改。如果僅僅退出不保存,可以輸入q

此時command+Q或source配置文件後,iTerm2變了模樣:

https://raw.githubusercontent.com/sirius1024/pubimgs/master/blogs/iterm2/12.png

8. 安裝高亮插件

這是oh my zsh的一個插件,安裝方式與theme大同小異:

cd ~/.oh-my-zsh/custom/plugins/

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git
vi ~/.zshrc

這時我們再次打開zshrc文件進行編輯。找到plugins,此時plugins中應該已經有了git,我們需要把高亮插件也加上:

https://raw.githubusercontent.com/sirius1024/pubimgs/master/blogs/iterm2/13.png

請務必保證插件順序,zsh-syntax-highlighting必須在最後一個。

然後在文件的最後一行添加:

source ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

按一下esc調出vi命令,輸入:wq保存並退出vi模式。

執行命令使剛纔的修改生效:

source ~/.zshrc

所有配置至此結束。下面提供另外的功能

9. 可選擇、命令補全

跟代碼高亮的安裝方式一樣,這也是一個zsh的插件,叫做zsh-autosuggestion,用於命令建議和補全。

cd ~/.oh-my-zsh/custom/plugins/

git clone https://github.com/zsh-users/zsh-autosuggestions
vi ~/.zshrc

找到plugins,加上這個插件即可:

https://raw.githubusercontent.com/sirius1024/pubimgs/master/blogs/iterm2/15.png

插件效果:

https://raw.githubusercontent.com/sirius1024/pubimgs/master/blogs/iterm2/16.png

有同學說補全命令的字體不太清晰,與背景顏色太過相近,其實可以自己調整一下字體顏色。

Preferences -> Profiles -> Colors 中有Foreground是標準字體顏色,ANSI Colors中Bright的第一個是補全的字體顏色。

10. 隱藏前綴

類似於Bash,在~/.zshrc這個文件中修改,打開後,隨便找個位置(最好靠上面一點方便查看)加上一行DEFAULT_USER=$USER即可。

效果:

11.預覽

# 預覽code
brew cask install qlcolorcode
#預覽Markdown
brew cask install qlmarkdown

Mac的預覽本身足夠強大,基於Mac這個功能,很多人開發了非常方便的預覽插件,可以利用homebrew方便的下載。有人也總結了一個list,包含各種預覽插件:

https://github.com/sindresorhus/quick-look-plugins

效果:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章