阿新

iTerm2主题配置与常用技巧
[TOC]序系统:macOS Sierra 10.12.6iTerm2版本:3.1.4最终效果:
扫描右侧二维码阅读全文
17
2018/05

iTerm2主题配置与常用技巧

[TOC]

  • 系统:macOS Sierra 10.12.6
  • iTerm2版本:3.1.4

最终效果:


下载安装

  1. 官网下载压缩包:http://www.iterm2.com/downloads.html
  2. 双击解压,将iTerm2.app拷贝到应用程序 完成安装!

配置主题

  • 打开iTerm2
  • 执行命令:curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh
  • 执行命令:sudo easy_install pip
  • 执行命令:pip install powerline-status
  • 安装字体库
  • 安装配色方案

双击 Solarized Dark.itermcolors

  • 在iTerm2中配置(若未找到,重启iTerm2)
  • 配置agnoster主题
ZSH_THEME="agnoster"
  • 配置指令高亮(zsh-syntax-highlighting)

修改文件:vi ~/.zshrc,在文件最后添加:

source ~/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
plugins=(zsh-syntax-highlighting)
  • 重启iTerm2,若在最上文没有错误或警告则表示配置成功
  • 完成!

ps: 配置后,~/.zshrc相当于文件:~/.bash_profile

常用命令

命令描述
⌘ + n新建窗口
⌘ + t新建标签页
⌘ + w关闭当前页
⌘ + 数字 或 ⌘ + 方向键切换标签页
⌘ + enter切换全屏
⌘ + d左右分屏
⇧⌘ + d上下分屏
⌘ + ;自动补全历史记录
⇧⌘ + h自动补全剪贴板历史
⌥⌘ + e查找所有来定位某个标签页
⌘ + r 或 ⌃ + l清屏
⌘ + /显示光标位置
⌥⌘ + b历史回放
⌘ + f查找,然后用 tab 和 ⇧ + tab 可以向右和向左补全,补全之后的内容会被自动复制, 还可以用 ⌥ + enter 将查找结果输入终端
⌘ + o 或 ⇧⌘ + b打个profile列表
⇧⌘ + e打开/关闭操作时间轴

设置自动SSH远程登录服务器

  • 创建脚本文件,名称任意(如:touch ~/.ssh/login)添加内容:
#!/usr/bin/expect
set timeout 30
spawn ssh -p [lindex $argv 3] [lindex $argv 1]@[lindex $argv 0]
expect {
        "(yes/no)?"
        {send "yes\n";exp_continue}
        "password:"
        {send "[lindex $argv 2]\n"}
}
interact
  • 打开iTerm2配置页,添加一个profile,在Command中输入:
脚本绝对路径 ip地址 用户名 密码 端口号
如:
expect ~/.ssh/login 127.0.0.1 root root123 22

如图所示:

注意: 上图第3步中,命令开头少了expect

  • 右击iTerm2内容框找到新建的profile即可连接

设置rzsz

参考:http://blog.csdn.net/citywolf4/article/details/49071679

  • 安装lrzsz
  • mac:$ brew install lrzsz
  • linux:$ yum install lrzsz$ apt-get install lrzsz
  • 下载zmoden脚本
  1. git:https://github.com/mmastrac/iterm2-zmodem
  2. 下载:iterm2-send-zmodem.sh(上传脚本)/ iterm2-recv-zmodem.sh(下载脚本)

本文提供俩脚本具体内容:

#!/bin/bash
# Author: Matt Mastracci (matthew@mastracci.com)
# AppleScript from http://stackoverflow.com/questions/4309087/cancel-button-on-osascript-in-a-bash-script
# licensed under cc-wiki with attribution required 
# Remainder of script public domain

osascript -e 'tell application "iTerm2" to version' > /dev/null 2>&1 && NAME=iTerm2 || NAME=iTerm
if [[ $NAME = "iTerm" ]]; then
    FILE=`osascript -e 'tell application "iTerm" to activate' -e 'tell application "iTerm" to set thefile to choose file with prompt "Choose a file to send"' -e "do shell script (\"echo \"&(quoted form of POSIX path of thefile as Unicode text)&\"\")"`
else
    FILE=`osascript -e 'tell application "iTerm2" to activate' -e 'tell application "iTerm2" to set thefile to choose file with prompt "Choose a file to send"' -e "do shell script (\"echo \"&(quoted form of POSIX path of thefile as Unicode text)&\"\")"`
fi
if [[ $FILE = "" ]]; then
    echo Cancelled.
    # Send ZModem cancel
    echo -e \\x18\\x18\\x18\\x18\\x18
    sleep 1
    echo
    echo \# Cancelled transfer
else
    /usr/local/bin/sz "$FILE" -e -b
    sleep 1
    echo
    echo \# Received $FILE
fi

↑↑↑ iterm2-send-zmodem.sh

#!/bin/bash
# Author: Matt Mastracci (matthew@mastracci.com)
# AppleScript from http://stackoverflow.com/questions/4309087/cancel-button-on-osascript-in-a-bash-script
# licensed under cc-wiki with attribution required 
# Remainder of script public domain

osascript -e 'tell application "iTerm2" to version' > /dev/null 2>&1 && NAME=iTerm2 || NAME=iTerm
if [[ $NAME = "iTerm" ]]; then
    FILE=`osascript -e 'tell application "iTerm" to activate' -e 'tell application "iTerm" to set thefile to choose folder with prompt "Choose a folder to place received files in"' -e "do shell script (\"echo \"&(quoted form of POSIX path of thefile as Unicode text)&\"\")"`
else
    FILE=`osascript -e 'tell application "iTerm2" to activate' -e 'tell application "iTerm2" to set thefile to choose folder with prompt "Choose a folder to place received files in"' -e "do shell script (\"echo \"&(quoted form of POSIX path of thefile as Unicode text)&\"\")"`
fi

if [[ $FILE = "" ]]; then
    echo Cancelled.
    # Send ZModem cancel
    echo -e \\x18\\x18\\x18\\x18\\x18
    sleep 1
    echo
    echo \# Cancelled transfer
else
    cd "$FILE"
    /usr/local/bin/rz -E -e -b
    sleep 1
    echo
    echo
    echo \# Sent \-\> $FILE
fi

↑↑↑ iterm2-recv-zmodem.sh

  • 将俩脚本放到自定义目录,如:
/User/vanki/iterm2_conf/iterm2-send-zmodem.sh
/User/vanki/iterm2_conf/iterm2-recv-zmodem.sh
  • 配置iterm2 trigger
  1. 打开iterm2
  2. 快捷键command + ,打开配置 -> Profiles -> Default -> Advanced -> TriggersEdit按钮,在弹出的界面配置以下参数:
Regular ExpressionActionParametersInstant
**B0100Run Silent Coprocess/User/vanki/iterm2_conf/iterm2-send-zmodem.sh选中
**B00000000000000Run Silent Coprocess/User/vanki/iterm2_conf/iterm2-recv-zmodem.sh选中

如图:

ps:可以快捷将选中的profile配置复制给其它profile中,操作如下:

快捷键command + ,打开配置 -> Profiles > 左下角:Other Actions -> Bulk Copy From Selected Profile...

文档摘录自:http://www.qiqinote.com/note/232.html

Last modification:June 21st, 2018 at 05:45 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment