iTerm2的安裝
1. 直接官網下載
下載地址: https://www.iterm2.com/downloads.html
下載的是壓縮文件
,解壓后直接雙擊執行程序文件,或者直接將它拖到 Applications 目錄下即可。
2. 使用Homebrew安裝
brew cask install iterm2
Homebrew
的安裝(已安裝Homebrew的請忽略此操作)
# install brew
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
# uninstall brew
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/HomebrewUninstall.sh)"
# cat version
brew -v
# update
brew update
# 自檢
/usr/local/bin/brew doctor
iTerm2的配置
1. 配置Oh My Zsh
Oh My Zsh
是對主題的進一步擴展,下載地址https://github.com/robbyrussell/oh-my-zsh
- 一鍵安裝:
wget
方式
$sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
wget
的安裝(已安裝Wget的請忽略此操作)
# install
brew install wget
# 查看版本
wget —version
- 手動安裝 :
git
地址https://github.com/ohmyzsh/ohmyzsh
# clone到本地
git clone https://github.com/ohmyzsh/ohmyzsh.git
# 復制文件夾
cp -r ohmyzsh ~/.oh-my-zsh
# 復制配置文件
cp ohmyzsh/templates/zshrc.zsh-template ~/.zshrc
# 切換shell
chsh -s /bin/zsh
打開終端發現權限問題,解決如下:
chmod 755 /usr/local/share/zsh
chmod 755 /usr/local/share/zsh/site-functions
# 修改配置文件
vim ~/.zshrc
輸入i
進入編輯模式
,將ZSH_THEME=
""編輯為 ZSH_THEME="agnoster"
按下esc
鍵,退出編輯,:wq
保存退出。
2. 配置iTerm2的主題
Dracula
主題:https://blog.csdn.net/daiyuhe/article/details/88667875
iTerm2
最常用的主題是 Solarized Dark theme
,下載地址:
http://ethanschoonover.com/solarized
https://github.com/altercation/solarized github地址
# clone到本地
git clone https://github.com/altercation/solarized.git
打開 iTerm2
,按Command +,
鍵,打開 Preferences
配置界面,然后 Profiles
-> Colors
-> Color Presets
,在下拉列表中選擇 Import
,選擇clone到本地的solarized
->iterm2-colors-solarized
->Solarized Dark.itermcolors
文件。導入成功后,在 Color Presets
下選擇 Solarized Dark
主題,就可以了。
3. 設置 iTerm2 的背景圖片
打開 iTerm2,按Command +,
鍵,打開Preferences
配置界面Profiles
-> Window
->Background mage
,選擇一張自己喜歡的背景圖。
4. 配置Meslo字體
使用 Solarized Dark
主題,需要 Meslo
字體支持,要不然會出現亂碼的情況。
- 安裝
PowerLine
(狀態欄工具 )
- 先安裝pip命令 :pip是python的一個維護命令
#方式一
sudo easy_install pip
#方式二:下載腳本文件 get-pip.py
curl 'https://bootstrap.pypa.io/get-pip.py' > get-pip.py
# 執行腳本文件
sudo python3 get-pip.py
- 安裝Powerline:(—user好像是表示基于用戶的權限)
pip install powerline-status --user
- 安裝
PowerFonts
字體
#—depth=1表示值clone最近一次commit的
git clone https://github.com/powerline/fonts.git --depth=1
cd fonts
# 運行install shell
./install.sh
然后打開iTerm2
,按Command + ,
鍵,打開Preferences
配置界面,然后Profiles
-> Text
-> Font
->Chanage Font
,選擇 Meslo LG S Regular for Powerline
字體。
5. 配置高亮
配置后,特殊
命令和錯誤
命令,會有高亮顯示。
- 使用brew安裝
# install
brew install zsh-syntax-highlighting
# uninstall
brew uninstall zsh-syntax-highlighting
- clone到本地安裝
cd ~/.oh-my-zsh/custom/plugins/
# clone到本地
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git
# 編輯配置文件
vim ~/.zshrc
輸入i
進入編輯模式
,將plugins=
""編輯為 plugins=(git zsh-syntax-highlighting)
,如圖
注意
:要保證zsh-syntax-highlighting
在plugins
字段的最后一個
再在配置文件最后一行增加下面配置:
#git方式安裝
source ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
#brew方式安裝,則用以下配置
source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
然后按下esc
鍵退出編輯,輸入:wq
保存退出。如圖
6. 配置自動建議填充
這個功能是非常實用的,可以方便我們快速的敲命令。
# clone到指定目錄
git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions
# 編輯配置文件
vim ~/.zshrc
輸入i
進入編輯模式
,將plugins=
""編輯為 plugins=(git zsh-autosuggestions zsh-syntax-highlighting)
,然后按下esc
鍵退出編輯,輸入:wq
保存退出。如圖
注意
:要保證zsh-syntax-highlighting
在plugins
字段的最后一個
7. 配置快速隱藏和顯示iTerm2 窗口
打開 iTerm2
,按Command + ,
鍵,打開Preferences
配置界面,然后Profiles
→ Keys
→Hotkey
,自定義一個快捷鍵即可。如圖:
8. 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 搜索命令歷史
9. 配置autojump
- git方式下載
git clone https://github.com/joelthelion/autojump.git
- 進入autojump文件夾
cd autojump
- 執行腳本文件
. /install.py
- 如果提示找不到
python
但又安裝了python
,建立軟鏈接
#查看python的位置
which python3
#位置為/Library/Frameworks/Python.framework/Versions/3.11/bin/python3
#建立軟鏈接
ln -s /Library/Frameworks/Python.framework/Versions/3.11/bin/python3 /Library/Frameworks/Python.framework/Versions/3.11/bin/python
- 修改配置文件
vim ~/.zshrc
在配置文件中添加以下代碼:
# Add wisely, as too many plugins slow down shell startup.
plugins=(
git
autojump
zsh-autosuggestions
zsh-syntax-highlighting
)
[[ -s ~/.autojump/etc/profile.d/autojump.sh ]] && . ~/.autojump/etc/profile.d/autojump.sh
- 讓配置文件生效
source ~/.zshrc
10.Go2Shell實現在文件目錄中打開iTerm2
待更新