iterm2的下載安裝與配置


 

2021.4.8

iterm2分屏快捷鍵:

command + d:垂直分屏,

command + shift + d:水平分屏。

參考:https://www.jianshu.com/p/4a27bb4c216c

 

 

2020.12.30

今天在運行okexchaind命令的時候又遇到zsh: command not found: 的問題:

(先用 chsh -s /bin/bash 和 chsh -s /bin/sh 方法不管用)

解決方法:把 bash shell 中.bash_profile 全部環境變量加入zsh shell里就好

第一步,在終端執行

open ~/.zshrc

第二步,找到 "# User configuration",在其下面添加下面內容

source ~/.bash_profile
如果沒有'# User configuration',就直接把上面內容添加到 ~/.zshrc 里面

第三步,在終端里執行

source ~/.zshrc

 

 

10.24

9月份的時候安裝了iterm2,但沒有安裝命令提示。今天再加上:

Oh My Zsh安裝
curl方式
$ curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh
wget方式
$ wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O - | sh


安裝完之后,關閉當前終端,並重新打開一個,oh my zsh的默認主題是robbyrussell

source .zshrc的時候報錯:

-bash: ~/.oh-my-zsh/tools/check_for_upgrade.sh: line 31: syntax error near unexpected token `)'
-bash: ~/.oh-my-zsh/tools/check_for_upgrade.sh: line 31: `() {'
-bash: autoload: command not found
-bash: ~/.oh-my-zsh/oh-my-zsh.sh: line 39: syntax error near unexpected token `('
-bash: ~/.oh-my-zsh/oh-my-zsh.sh: line 39: `for plugin ($plugins); do'

 

查看當前已安裝shells:

cat /etc/shells

mac os 系統默認的終端為bash,切換該終端為zsh,可以用以下命令

chsh -s /bin/zsh

【重要:生效后打開新窗口】

更改zsh配置文件:

vim ~/.zshrc

更改完配置記得運行:

source ~/.zshrc

【重要:再改回去】

還原默認shell:

chsh -s /bin/bash

 

如果是item2 + oh-my-zsh + agnoster主題組合,cd到 ~/.oh-my-zsh/themes/然后 vim agnoster.zsh-theme,找到如下代碼

# Context: user@hostname (who am I and where am I)
prompt_context() {
  if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
   # 修改如下代碼,標灰色的地方可以自定義
   # prompt_segment black default "%(!.%{%F{yellow}%}.)$USER@%m"
   prompt_segment black default "%(!.%{%F{yellow}%}.)$USER@Mac"
  fi
}

修改打開終端的默認shell

  • 打開VSCode的設置(Preferences>User Settings)
  • 搜索terminal.integrated.shell.osx 的 並把它的值改 為 你的zsh 安裝路徑

 

安裝PowerLine

安裝powerline的方式依然簡單,也只需要一條命令:

pip install powerline-status --user

sudo easy_install pip # 如果沒有安裝

 

 

安裝PowerFonts

安裝字體庫需要首先將項目git clone至本地,然后執行源碼中的install.sh。

在你習慣的位置新建一個文件夾,如:~/Desktop/OpenSource/

# 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字體。有L、M、S可選,看個人喜好:
 

安裝配色方案

配色方案在使用VIM或Colorful Log時會變得非常有用,同時界面也不會一片黑綠一樣死板。

同樣使用git clone的方式下載源碼進行安裝:


cd ~/Desktop/OpenSource

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中根據個人喜好選擇這兩種配色中的一種即可:
 
Solarized Dark
Solarized Light


安裝主題

下載agnoster主題,執行腳本安裝:


cd ~/Desktop/OpenSource

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

cd oh-my-zsh-agnoster-fcamblor/

./install
拷貝完成后,執行命令打開zshrc配置文件,將ZSH_THEME后面的字段改為agnoster。
 
vi ~/.zshrc
 
ZSH_THEME="agnoster"  # 默認的是# ZSH_THEME="robbyrussell"

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

此時command+Q或source配置文件后,iTerm2變了模樣:帶箭頭了。


安裝高亮插件

這是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,我們需要把高亮插件也加上:

plugins=(
  git
  zsh-syntax-highlighting
)
 

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

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

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

 

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

 

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


source ~/.zshrc

至此大功告成,請看最終效果圖:

 

背景圖片取自微軟Surface Studio的4K壁紙(將近12MB大小),非常漂亮,需要的可以自取:

https://pan.baidu.com/s/1LKd4ghGyyNI6UwHhOHvfaA
提取碼: snrd

更換背景圖片方式:iTerm2 -> Preferences -> Profiles -> Window -> BackGround Image勾選圖片即可。

 

可選擇、命令補全

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


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

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

vi ~/.zshrc

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

plugins=(
  git
  zsh-autosuggestions
  zsh-syntax-highlighting
)

 

插件效果:

 

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

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



 
參考:
iTerm2 + Oh My Zsh 打造舒適終端體驗
https://www.jianshu.com/p/9c3439cc3bdb
 

 

2020-09

 

1,下載

到官網

2,安裝

解壓zip,打開

3,配置

接下來就設置iterm2支持ssh不要輸入密碼登錄
第一步: 創建shell命令文件,具體的路徑自己放置,示例:/Users/yuml/bin/iterm2login.sh

#!/usr/bin/expect

set timeout 30
spawn ssh -p [lindex $argv 0] [lindex $argv 1]@[lindex $argv 2]
expect {
        "(yes/no)?"
        {send "yes\n";exp_continue}
        "password:"
        {send "[lindex $argv 3]\n"}
}
interact

shell文件是expect語言腳本,可以自動和網絡交互,基本原理就是解析ssh的命令文本返回,根據文本內容匹配,執行對應的操作,send就是模擬人工輸入。

可以丟到任意一個文件夾下面,其中[lindex $argv 0], [lindex $argv 1], [lindex $argv 2], [lindex $argv 3] 分別代表着端口號/用戶名/服務器地址/ 密碼4個參數。

有時候不需要指定端口,就可以在腳本中刪除-p [lindex $argv 0],同時記得改后面argv的索引(argv1 => argv0)

 


第二步: 設置iterm2,在profiles中建立一個新profile,配置如192.168.100.127中描述填寫。

profile設置
Name: 填寫便於記憶的名稱
Login shell -> Send text at start: /Users/yuml/bin/iterm2login.sh 22 root 192.168.100.127 password

 

操作流程

  • 將這個文件 item2login.sh 復制到 /usr/local/bin (任意路徑)就可以了。 然后在iTerm2里面配置。
  • 打開ITerm2的Profiles菜單並添加新的profile
  • 在Command欄下的”Send text at start“處填入:item2login.sh 22 chenyuan 192.168.230.133 chenyuan

 


第三步: 運行profile, 在iterm2的頂部工具欄有一欄Profiles,就可以看到對應的profle,雙擊就可以了。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM