歡迎來我的博客閱讀:
「打造高效個性Terminal(一)之 iTerm」
「打造高效個性Terminal(二)之 zsh」
oh-my-zsh
如果說iTerm塑造了一個婀娜多姿顏值高的貌美姑娘,那么zsh就是給她塑造了一個柔情俠骨百事通的女漢子之心。
簡介 <small>Introduction</small>
對于zsh的作用,摘自池建強老師的一段:
目前常用的 Linux 系統和 OS X 系統的默認 Shell 都是 bash,但是真正強大的 Shell 是深藏不露的 zsh, 這貨絕對是馬車中的跑車,跑車中的飛行車,史「終極 Shell」,但是由于配置過于復雜,所以初期無人問津,很多人跑過來看看 zsh 的配置指南,什么都不說轉身就走了。直到有一天,國外有個窮極無聊的程序員開發出了一個能夠讓你快速上手的zsh項目,叫做「oh my zsh」,Github 網址是:https://github.com/robbyrussell/oh-my-zsh。
oh-my-zsh 是一個社區驅動用于管理zsh的框架,囊括了140多個主題,200多個可選插件(如rails, git, OSX, hub, brew, ant, php, python etc.)。
安裝 <small>Installation</small>
via curl
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
via wget
sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
配置 <small>Configuration</small>
zsh的配置主要集中在用戶當前目錄的.zshrc
里,用vim或者你喜歡的其他編輯器打開這個文件,在里面可以修改主題、插件以及定義自己的環境變量等操作。
主題 <small>Themes</small>
用vim打開~/.zshrc
中,可以看到這樣配置
...
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME="robbyrussell"
...
修改ZSH_THEME
的值就可以更換主題。
默認的主題是robbyrussell
,這個并不是最精彩,也并不是最簡單的一個,只是對于其作者Robby來說最適合的一個。
可以通過訪問~/.oh-my-zsh/themes/
目錄查看哪些可選的主題
$ tree themes
themes
├── 3den.zsh-theme
├── Soliah.zsh-theme
├── adben.zsh-theme
├── af-magic.zsh-theme
├── afowler.zsh-theme
├── agnoster.zsh-theme
...
0 directories, 141 files
更多關于各個主題的詳細介紹見 zsh themes,另外還有不少并不是自帶的主題,見more external themes
Powerline Fonts
如果你查看過zsh的主題列表的話,你會發現不少主題會有這樣的樣式,
然而,當你選擇了這樣的主題,會發現實際是這樣的
因為,這些主題都依賴于一種字體powerline fonts,powerline fonts
是vim增強組件vim powerline附屬的字體,如果要使用依賴這種字體的主題,要在系統中安裝該字體。
安裝 powerline fonts
// 下載powerline fonts項目
git clone https://github.com/powerline/fonts
// 執行安裝
./fonts/install.sh
配置iTerm
在Preperence → Profiles → Text → Front
中,
和Preperence → Profiles → Text → Non-ASCII Font
中
改變字體為Sauce Code Powerline
插件 <small>Plugins</small>
用vim打開~/.zshrc
中,可以看到這樣配置
...
# Which plugins would you like to load? (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)
...
修改plugins
的值就可以修改或添加插件。
下面介紹幾款我常用的插件
autojump
A cd command that learns - easily navigate directories from the command line
一款快捷跳轉目標路徑的插件,支持模糊匹配,自動補全,歷史記錄等功能。
dirhistory
This plugin allows you to navigate the history of previous current-working-directories using ALT-LEFT and ALT-RIGHT. ALT-LEFT moves back to directories that the user has changed to in the past, and ALT-RIGHT undoes ALT-LEFT.
一款支持目錄的上翻,下翻功能的插件。
osx
This plugin provides a few utilities to make it more enjoyable on OSX.
一款增加了一些在OSX上實用的命令插件。
Command | Description |
---|---|
tab |
Open the current directory in a new tab |
ofd |
Open the current directory in a Finder window |
pfd |
Return the path of the frontmost Finder window |
pfs |
Return the current Finder selection |
cdf |
cd to the current Finder directory |
pushdf |
pushd to the current Finder directory |
quick-look |
Quick-Look a specified file |
man-preview |
Open a specified man page in Preview app |
git
The git plugin provides many aliases and a few useful functions.
一款提供git別名命令以及一些方法命令的插件
git-extras
一款擴展了不少方便快捷git命令的插件
More Plugins
更多的插件介紹見 zsh plugins
vi(vim) 基礎
使用命令行的時候,難免會遇到要編輯文檔的時刻,盡管不是vim黨,但是如果掌握vim的基本操作,對效率還是有大大提升的。
vi與vim的關系
簡單來說,vi是老師的文字處理器,不過功能已經很齊全了,但是還是有可以進步的地方。vim則可以說是程序開發者的一項很好用的工具,就連vim的官方網站(http://www.vim.org/)自己也說vim是一個「程序開發工具」而不是文字處理軟件。
三種模式
基本上vi中共分為3種模式,分別是「一般模式」,「編輯模式」與「命令行模式」
一般模式
以vi打開一個文件,默認就是一般模式,這個模式中,可以按下i
來進入編輯模式,按下ESC
則退出編輯模式回到一般模式。在這個模式中可以刪除字符、刪除行、復制、黏貼。編輯模式
編輯模式能真正的編輯文本。命令模式
在一般模式中,輸入:
,/
,?
中的一個可以進入命令行模式,進行諸如數據查找操作,讀取、保存、離開vi等等操作。
常用操作
掌握下面的十一個命令,就足夠你在vim中生存了。
移動光標
- hjkl : 你也可以使用光標鍵 (←↓↑→). 注: j 就像下箭頭。
行操作
- dd : 刪除當前行,并把刪除的行存到剪貼板里
- yy : 復制當前行。
- p : 黏貼剪貼板
保存退出
- :w : 保存已編輯的文集
- :q : 退出編輯
- :wq : 保存并退出
- :help : 顯示相關命令的幫助(退出幫助需要輸入:q)
搜索
- /word : 向下尋找一個名為word的字符串
- ?word : 向上尋找一個名為word的字符串
- n : 重復前一個查找的操作
文末福利,安撫你的強迫癥
感謝你能耐心的看到這里,給你安利一個強迫癥患者福音的窗口控制工具:Spectacle
Spectacle能通過快捷鍵,很輕易的排列好窗口的大小。
參考
http://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively
https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins
http://www.vim.org/
http://macshuo.com/?p=676
http://swiftcafe.io/2015/07/25/iterm/