小白也能看懂的ArrayList的擴容機制
一、iTerm2簡介:
Mac OS
自帶的終端,用起來雖然有些不太方便,介面也不夠友好,iTerm2
是一款相對比較好用的終端工具.iTerm2
常用操作包括主題選擇、宣告高亮、自動填充建議、隱藏使用者名稱和主機名、分屏效果等.
先來看效果圖:
二、下載及安裝
補充一些關於shell的介紹:
Mac系統預設使用dash作為終端,但是新的Mac系統已經預設使用zsh.檢視方法:
可以自行檢視系統當前 shell
$ cat /etc/shells
/bin/bash
/bin/csh
/bin/dash
/bin/ksh
/bin/sh
/bin/tcsh
/bin/zsh
以及切換shell
chsh -s /bin/zsh
chsh -s /bin/bash
其中,
bash的配置檔案是 -/.bash_profile
zsh的配置檔案是-/.zshrc
位置在使用者家目錄下,為隱藏檔案
1.在finder根目錄中command + shift + .
顯示隱藏檔案即可看到.同時可以看到bash 、csh 、dash 、zsh等都在這個目錄下,
iTerm2
下載地址:https://www.iterm2.com/downloads.html
1、
下載的是壓縮檔案,解壓後直接雙擊執行程式檔案,或者直接將它拖到 Applications 目錄下。
2、
也可以直接使用Homebrew
進行安裝:
$ brew cask install iterm2
安裝完開啟,這是iTem最初的樣子,基於此可以安裝各種外掛來優化了...
三 、配置 iTerm2 主題
iTerm2 最常用的主題是 Solarized Dark theme,下載地址:
http://ethanschoonover.com/solarized
https://github.com/altercation/solarized github地址
下載的是壓縮檔案,解壓,然後開啟 iTerm2,按Command +
鍵,開啟 Preferences 配置介面,然後Profiles -> Colors -> Color Presets,在下拉列表中選擇 Import,選擇剛才解壓的solarized->iterm2-colors-solarized->Solarized Dark.itermcolors檔案.匯入成功後,在 Color Presets下選擇 Solarized Dark 主題,就可以了。
效果圖:
三 、設定 iTerm2 背景圖片
開啟 iTerm2,按Command +
鍵,開啟 Preferences 配置介面Profiles -> Window->Background mage,選擇一張自己喜歡的背景圖.
四 、 配置 Oh My Zsh
Oh My Zsh
是對主題的進一步擴充套件,下載地址https://github.com/robbyrussell/oh-my-zsh
1.一鍵安裝:
via curl方式:
$ sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
via wget方式:
$sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
2.手動方式安裝,如下:
(git地址: https://github.com/ohmyzsh/ohmyzsh)
## 找到倉庫, 然後clone到本地
git clone https://github.com/ohmyzsh/ohmyzsh.git
## 把倉庫複製到 .oh-my-zsh目錄
cp -r ohmyzsh ~/.oh-my-zsh
## 複製.zshrc
cp ohmyzsh/templates/zshrc.zsh-template ~/.zshrc
## shell換成zsh
chsh -s /bin/zsh
3.安裝好之後,需要把 Zsh 設定為當前使用者的預設 Shell(這樣新建標籤的時候才會使用 Zsh):
$ chsh -s /bin/zsh
4.然後,將主題修改為ZSH_THEME="agnoster"
。
$ vim ~/.zshrc
輸入i
進入編輯模式,將ZSH_THEME=""
編輯為 ZSH_THEME="agnoster"
按下esc
鍵,退出編輯,:wq
儲存退出:
修改成功!
agnoster
是比較常用的 zsh 主題之一,你可以挑選你喜歡的主題,zsh 主題列表:https://github.com/robbyrussell/oh-my-zsh/wiki/themes
補充:
上面提到的via wget安裝方式需要安裝wget,方法如下:
直接終端使用homebrew安裝(前提是已經安裝了homebrew)
安裝命令:
$brew install wget
檢驗是否安裝成功:
$ wget http://www.arefly.com/
五 、配置 Meslo 字型
使用上面的主題,需要 Meslo 字型支援,要不然會出現亂碼的情況,字型下載地址:Meslo LG M Regular for Powerline.ttf
下載好之後,找到對應的字型,直接在 Mac OS 中安裝即可。
然後開啟 iTerm2,按Command + ,
鍵,開啟 Preferences 配置介面,然後Profiles -> Text -> Font -> Chanage Font
,選擇 Meslo LG M Regular for Powerline 字型。
六 、宣告高亮
特殊命令和錯誤命令,會有高亮顯示。
使用 Homebrew 安裝:
$ brew install zsh-syntax-highlighting
安裝成功之後,編輯vim ~/.zshrc檔案,在最後一行增加下面配置:
source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
方式2
執行下面指令自動安裝
$ git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting
然後編輯vim ~/.zshrc
檔案,找到plugins配置,增加zsh-syntax-highlighting
外掛。
這個功能是非常實用的,可以方便我們快速的敲命令。
配置步驟,先克隆zsh-autosuggestions專案,到指定目錄:
$ git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions
然後編輯vim ~/.zshrc
檔案,找到plugins配置,增加zsh-autosuggestions
外掛。
八、iTerm2 快速隱藏和顯示窗體:
開啟 iTerm2,按Command + ,
鍵,開啟 Preferences 配置介面,然後Profiles → Keys →Hotkey,自定義一個快捷鍵就可以了。
九、iTerm2 隱藏使用者名稱和主機名
有時候我們的使用者名稱和主機名太長,終端顯示的時候會很不好看,我們可以手動去除。
編輯vim ~/.zshrc
檔案,增加DEFAULT_USER="SKong"
配置.
但是: 我的電腦沒生效,至今未找到原因~~~
補充:已經找到原因,這個地方應該設定為: DEFAULT_USER="你電腦的使用者名稱"
比如:我的電腦使用者名稱為pactepacterara,則DEFAULT_USER="pactepacterara"
效果對比:
我們可以通過whoami
命令,檢視當前使用者
十、iTerm2 快捷命令
在iterm2中,選中某個路徑或者某個詞彙,iterm2就自動複製了,很方便。
command + enter 進入與返回全屏模式
command + t 新建標籤
command + w 關閉標籤
command + 數字 command + 左右方向鍵 切換標籤
command + enter 切換全屏
command + f 查詢
command + d 水平分屏
command + shift + d 垂直分屏
command + option + 方向鍵 command + [ 或 command + ] 切換螢幕
command + ; 檢視歷史命令
command + shift + h 檢視剪貼簿歷史
ctrl + u 清除當前行
ctrl + l 清屏
ctrl + a 到行首
ctrl + e 到行尾
ctrl + f/b 前進後退
ctrl + p 上一條命令
ctrl + r 搜尋命令歷史
十、解除安裝 oh-my-zsh
進入到.oh-my-zsh/tools目錄,依次執行
$cd .oh-my-zsh/tools
chmod +x uninstall.sh
./uninstall.sh
rm -rif .zshrc
補充
我們來看一下/.zshrc的檔案原始碼, 很多zsh的配置都在這裡面
vim ~/.zshrc