iTerm2教程|如何使用iTerm2對環境進行重新配色和美化?

ruijing1207發表於2020-11-10

這是一款輕巧但功能強大的Mac終端模擬軟體,是可替代Apple終端和iTerm的繼任者。那麼如何使用iTerm2對環境進行重新配置?今天macw小編就帶了iTerm2教程——如何使用iTerm2對環境進行重新配色和美化?
下載安裝iTerm2
首先,下載iTerm2來替換預設終端。在這裡插入圖片描述(可選)遷移配置
因為我之前也是Mac平臺,所以有一些配置可以在ITerm裡匯出,其實重新配置也都一樣,沒有什麼影響。
在原電腦上的iterm匯出配置:在這裡插入圖片描述然後在新電腦匯入:
如上圖 import JSON Profiles,然後設定為預設配置。在這裡插入圖片描述調整Status Bar
將iTerm2 自帶 theme 修改為 Minimal ( Preferences-Appearance-General-Theme ) 以達到頂欄沉浸式的效果
可以在Profiles選項卡,Session頁面最底部看到開啟選項。Status bar enabled 選項,勾選上即可開啟。點選右邊的 Configure Status Bar 按鈕可設定顯示的內容。
可以看到能顯示的內容非常多,把上方要顯示的內容拖動到下方 Active Components 區域即新增。
在Preference頁面中點選Appearance選項卡,可以設定Status bar的位置,修改 Status bar location,我這裡改到Bottom底部。在這裡插入圖片描述Status bar效果:在這裡插入圖片描述顯示的內容也可以自己調節:在這裡插入圖片描述設定zsh主題
配置主題:
只需要修改 .zshrc 檔案中的 ZSH_THEME=“xx” 屬性即可。
我目前使用的主題是:spaceship
按照github專案說明中的方法配置即可,或者參考本文下面的主題配置
前提:
安裝了zsh
安裝了powerline字型
然後把iTerm的字型設定為powerline,包括Font和Non-ASCII Font在這裡插入圖片描述下載主題檔案:
git clone https://github.com/denysdovhan/spaceship-prompt.git “$ZSH_CUSTOM/themes/spaceship-prompt” --depth=1
建立軟連線

ln -s “ Z S H C U S T O M / t h e m e s / s p a c e s h i p − p r o m p t / s p a c e s h i p . z s h − t h e m e " " ZSH_CUSTOM/themes/spaceship-prompt/spaceship.zsh-theme" " ZSHCUSTOM/themes/spaceshipprompt/spaceship.zshtheme""ZSH_CUSTOM/themes/spaceship.zsh-theme”
修改zsh配置
vim ~/.zshrc
修改:
ZSH_THEME=“spaceship”
生效:
source ~/.zshrc
然後就是主題的一些配置,配置說明參考這個檔案:
https://github.com/denysdovhan/spaceship-prompt/blob/master/docs/Options.md
具體配置顯示哪些內容,根據文件在 ./zshrc 中新增就好。這裡說一下我的配置:
PS:顏色數值參考這個https://upload.wikimedia.org/wikipedia/commons/1/15/Xterm_256color_chart.svg
我的配置
設定顯示時間
SPACESHIP_TIME_SHOW=“true”
設定顯示使用者名稱,並改使用者名稱顏色為猛男粉
SPACESHIP_USER_SHOW=“always”
SPACESHIP_USER_COLOR="212"在這裡插入圖片描述主題對應地址:
https://github.com/denysdovhan/spaceship-prompt
設定Oh-My-Zsh
什麼是Oh-My-Zsh?
Oh My Zsh是一款社群驅動的命令列工具,它基於zsh命令列,提供了主題配置,外掛機制,大大提高了可玩(用)性。提升使用效率還能使人愉快
輸入如下命令:
curl方式
sh -c “ ( c u r l − f s S L h t t p s : / / r a w . g i t h u b u s e r c o n t e n t . c o m / o h m y z s h / o h m y z s h / m a s t e r / t o o l s / i n s t a l l . s h ) " 或 者 使 用 w g e t : s h − c " (curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" 或者使用wget: sh -c " (curlfsSLhttps://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"使wgetshc"(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)”
配置Oh-My-Zsh
配置命令自動提示 關於外掛的配置,如果要看目前安裝了哪些外掛,可以在.zshrc中搜尋plugins關鍵字,獲得如下,也是我老電腦中的配置內容:
plugins=( git autojump zsh-autosuggestion zsh-syntax-highlighting )
關於命令提示
當我們輸入命令過程中,終端會自動提示你接下來可能要輸入的命令,這時按 → 便可輸出這些命令,非常方便。
效果可參考GitHub專案說明中的視訊
專案地址:https://github.com/zsh-users/zsh-autosuggestions
1、克隆專案到本地 $ZSH_CUSTOM/plugins 路徑下 `預設是 ·~/.oh-my-zsh/custom/plugins
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
2、編輯 ~/.zshrc 配置檔案,新增到plugins列表中
plugins=(zsh-autosuggestion)
3、新開一個終端視窗檢視效果在這裡插入圖片描述如果最後看不到提示的效果可能是顏色配置問題,參考GitHub專案說明中的修改方法去修改配置
配置語法高亮顯示
專案地址: https://github.com/zsh-users/zsh-syntax-highlighting
安裝方法:
推薦使用HomeBrew進行安裝:
1、brew安裝
brew install zsh-syntax-highlighting brew的專案地址 https://brew.sh/
2、在 ~/.zshrc 尾部,插入一行:
source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh vim中 直接使用 shift+g 可以跳轉的最後一行
3、生效配置
source ~/.zshrc
❗️不過這時產生了一些警告資訊:
➜ source ~/.zshrc
[oh-my-zsh] Insecure completion-dependent directories detected:
drwxrwxr-x 3 lanvnal admin 96 9 22 01:51 /usr/local/share/zsh
drwxrwxr-x 4 lanvnal admin 128 9 22 01:53 /usr/local/share/zsh/site-functions
[oh-my-zsh] For safety, we will not load completions from these directories until
[oh-my-zsh] you fix their permissions and ownership and restart zsh.
[oh-my-zsh] See the above list for directories with group or other writability.
[oh-my-zsh] To fix your permissions you can do so by disabling
[oh-my-zsh] the write permission of “group” and “others” and making sure that the
[oh-my-zsh] owner of these directories is either root or your current user.
[oh-my-zsh] The following command may help:
[oh-my-zsh] compaudit | xargs chmod g-w,o-w
[oh-my-zsh] If the above didn’t help or you want to skip the verification of
[oh-my-zsh] insecure directories you can set the variable ZSH_DISABLE_COMPFIX to
兩種解決方法:
1、按照安裝提示去修改對應目錄的許可權:
chmod 755 /usr/local/share/zsh
chmod 755 /usr/local/share/zsh/site-functions
2、在 ~/.zshrc 這個檔案中新增 ZSH_DISABLE_COMPFIX=true 即可。
配置autojump
效果:
實現目錄間快速跳轉,想去哪個目錄直接 j + 目錄名(甚至不用輸全),不用在頻繁的 cd 了
安裝方法:
1、brew安裝
brew install autojump
2、修改 ~/.zshrc 檔案,新增到plugins配置列表並在尾部追加如下內容:
[ -f /usr/local/etc/profile.d/autojump.sh ] && . /usr/local/etc/profile.d/autojump.sh
plugins中別忘了新增上autojump:
plugins=(
git
zsh-autosuggestion
autojump
)
然後source使他生效
PS:在brew安裝完會有提示輸出,按照提示來配置就好
Add the following line to your ~/.bash_profile or ~/.zshrc file (and remember to source the file to update your current session): [ -f /usr/local/etc/profile.d/autojump.sh ] && . /usr/local/etc/profile.d/autojump.sh
If you use the Fish shell then add the following line to your ~/.config/fish/config.fish: [ -f /usr/local/share/autojump/autojump.fish ]; and source /usr/local/share/autojump/autojump.fish
zsh completions have been installed to: /usr/local/share/zsh/site-functions
以上就是MacW小編為大家帶來的“iTerm2教程|如何使用iTerm2對環境進行重新配色和美化?”,本文關鍵詞:“iTerm2教程,iTerm2使用,終端軟體”。

相關文章