iTerm2安装配置使用指南
这篇文章主要介绍了如何在macOS上安装和配置iTerm2终端,包括安装oh-my-zsh、设置主题、安装字体和插件,以及一些高级配置和使用技巧。
mac平台最好用的终端
官方下载地址:
Downloads - iTerm2 - macOS Terminal Replacement
根据个人需求下载正式稳定版或者beta版,下载完成之后,双击打开zip包,解压至当前文件夹,
把解压好的 iTerm.app
拖到应用程序 然后从启动台中找它,双击打开双击打开iTerm.app,根据弹窗提示点击Move to Applications Folder即可。
打开iTerm2,左上角选择iTerm2,红框内容点击即可
访问iTerm2主题网站
https://github.com/mbadolato/iTerm2-Color-Schemes
mac下默认的Shell是bash,虽然bash的功能已经很强大了,但是zsh拥有更多的自定义空间,并支持各种丰富的扩展,可以实现更强大的命令补全,命令高亮,自动跳转等一系列功能,这些功能极大的提升了我们操作命令行的效率。其实吧,我觉得以上的都不是很重要,对大家最最最重要的一点就是:
“不管我行不行,我的工具要够炫,只要你被我的工具装到了,我至少胜利了一大半。”
工具胜利法,这一波又赢麻了。
当然使用zsh Shell 的代价是牺拖慢了一点点启动速度,不过这点几乎可以直接忽略不计,因为默认的 zsh 配置起来比较麻烦,一个叫 robbyrussel 的用户在 GitHub 上制作了一个配置文件 oh-my-zsh,该文件逐步的被大家接受,目前也是公认的较为流行的zsh 配置方式。
访问oh-my-zsh官网:
官网提供了两种安装方式,博主都贴在了下面,方便大家直接复制使用:
bash#Install oh-my-zsh via curl
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
#Install oh-my-zsh via wget
sh -c "$(wget https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"
咱们在1.2.2小节提供了Homwbrew的安装办法,如果使用wget安装方式,若终端提示未安装wget,直接在Shell输入以下命令行点击回车进行安装即可
bashbrew install wget
安装完成后我们需要把zsh设为默认的Shell,下面提供几个常用的命令,供大家参考:
bash#查看系统安装的所有Shell
cat /etc/Shells
bash#查看当前使用的Shell
echo $SHELL
bash#修改默认Shell为zsh
chsh -s /bin/zsh
修改默认Shell需要输入电脑密码,输入后回车即修改成功,博主默认使用的就是zsh,所以这里显示未修改。
安装完成后接下来我们对zsh主题进行修改,首先咱们可以使用以下的命令查看所有的oh-my-zsh自带主题
bashls ~/.oh-my-zsh/themes
是不是一脸懵逼,你肯定要问这么多主题,每个主题都是什么样的,哪个适合我呢?咱们可以进入下面的网站看下oh-my-zsh自带的部分主题显示效果:
找到自己喜欢的主题,接下来就可以进行主题修改了,博主以agnoster为例,展示下如何修改oh-my-zsh主题:
bashvim ~/.zshrc
进入如下界面,可以看到红框圈出来的即为主题配色方案:ZSH_THEME="agnoster”
agnoster
删除也可以不擅长,写入你喜欢的主题如果还是想用agnoster
就不用动了,显示为ZSH_THEME="agnoster"
ecs键
,输入:wq
退出编辑模式bashsource ~/.zshrc
后面涉及到的对此配置文件的修改均采用上面的方法,只是修改的内容不一样,不再赘述具体的操作。
当然如果你特别变态,对所有的主题都很喜欢,可以按照上面的修改步骤,把主题修改为
bashZSH_THEME="random"
这样你每启动一次终端,就会随机切换一个主题。
当然你也可以选择几个最喜欢的主题配置在图片中红框这一行
bashZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" "ys")
这样你的主题会在括号中配置的这几个主题中随机切换。
除此之外,你也可以排除你不想要的主题,在配置文件增加如下代码,在括号中写上自己不喜欢的主题名称,以空格隔开:
bashZSH_THEME_RANDOM_IGNORED=(pygmalion tjkirch_mod)
如果对自带的主题不太满意,可以进入下面的网站看下oh-my-zsh的部分第三方主题显示效果
https://github.com/ohmyzsh/ohmyzsh
可以根据自己的喜好进行下载安装。
iTerm2 修改主题之后,因为某些主题含有特殊字符或者表情,在操作的时候会出现乱码的情况,因此需要安装Meslo字体来兼容解决。
字体下载地址:
https://github.com/powerline/fonts
在fonts目录下找到 Meslo Slashed/Meslo LG M Regular for Powerline.ttf 字体
下载后直接安装即可。
bash#先使用git命令克隆
git clone https://github.com/powerline/fonts.git --depth=1
# 进入克隆到本地的fonts目录进行安装
cd fonts
./install.sh
# 删除克隆到本地的目录
cd ..
rm -rf fonts
打开iTerm2,打开Preferences配置界面,Profiles -> Text -> Font,选择 Meslo LG M Regular for Powerline 字体。
插件的安装,博主基本都提供了Homebrew
或者git
两种安装方式,大家根据习惯任选其一即可,无需重复安装。
此款插件在我们使用命令行的时候如果遇到特殊命令或者错误命令,会有高亮显示,可以及时进行提醒。
博主这边已经安装过了,这里直接提示已安装,未安装的同学直接输入以下命令等待安装完成即可:
bashbrew install zsh-syntax-highlighting
安装成功后,进行如下操作:
bash#编辑配置文件
vim ~/.zshrc
#在最后一行增加下面的代码
source /opt/homebrew/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
#退出编辑后执行使配置生效
source ~/.zshrc
这里如果还不清楚如何操作,请参考4.1.1自带主题这一小节,进行文件修改即可。
bashgit clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting
安装成功后,进行如下操作:
bash#编辑配置文件
vim ~/.zshrc
#找到plugins配置,在括号内增加zsh-syntax-highlighting,与其他插件之间使用空格分隔开
plugins=(zsh-syntax-highlighting)
#退出编辑后执行使配置生效
source ~/.zshrc
此款插件非常实用,大大加快了我们敲命令的速度。
直接输入以下命令等待安装完成即可:
bashbrew install zsh-autosuggestions
安装成功后,进行如下操作:
bash#编辑配置文件
vim ~/.zshrc
#在最后一行增加下面的代码
source /opt/homebrew/share/zsh-autosuggestions/zsh-autosuggestions.zsh
#退出编辑后执行使配置生效
source ~/.zshrc
bashgit clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions
安装成功后,进行如下操作:
bash#编辑配置文件
vim ~/.zshrc
#找到plugins配置,在括号内增加zsh-autosuggestions,与其他插件之间使用空格分隔开
plugins=(zsh-autosuggestions)
#退出编辑后执行使配置生效
source ~/.zshrc
此款插件可以帮助我们快速跳到常用的目录。
直接输入以下命令等待安装完成即可:
bashbrew install autojump
安装成功后,进行如下操作:
bash#编辑配置文件
vim ~/.zshrc
#在最后一行增加下面的代码
[[ -s $(brew --prefix)/etc/profile.d/autojump.sh ]] && . $(brew --prefix)/etc/profile.d/autojump.sh
#退出编辑后执行使配置生效
source ~/.zshrc
bash#github镜像
git clone git://github.com/joelthelion/autojump.git
#进入目录,执行安装命令
./install.py
在安装过程中,会在~/下建立.autojump文件夹,如果github镜像无法下载,请使用gitee镜像下载
bash#gitee镜像
git clone https://gitee.com/null_454_5218/autojump.git $ZSH_CUSTOM/plugins/autojump
#进入目录autojump中
cd $ZSH_CUSTOM/plugins/autojump
#执行安装命令
./install.py
安装成功后,进行如下操作:
bash#编辑配置文件
vim ~/.zshrc
#找到plugins配置,在括号内增加autojump,与其他插件之间使用空格分隔开
plugins=(autojump)
#在文件最后一行或者plugins=()后另起一行添加如下内容
[[ -s ~/.autojump/etc/profile.d/autojump.sh ]] && . ~/.autojump/etc/profile.d/autojump.sh
#退出编辑后执行使配置生效
source ~/.zshrc
当我们输入命令错误时,
输入fuck
,终端就会乖乖的给我们正确的指令选择了!
直接输入以下命令等待安装完成即可:
bashbrew install thefuck
安装成功后,进行如下操作:
bash#编辑配置文件
vim ~/.zshrc
#在最后一行增加下面的代码
eval $(thefuck --alias)
#退出编辑后执行使配置生效
source ~/.zshrc
当我们输入命令需要管理员身份时,不必让光标回到开始打一个sudo,可以直接
按两次ESC
,就会自动帮你加上sudo
直接输入以下命令完成即可:
js#编辑配置文件
vim ~/.zshrc
#找到 plugins 部分,确保 sudo 插件被添加到其中:
plugins=(
sudo
)
#退出编辑后执行使配置生效
source ~/.zshrc
打开iTerm2,打开Preferences配置界面,Profiles → Keys →configure Hotkey window,自定义一个快捷键就可以了。
通常在Shell中默认的我们的用户名和主机名,这两者加在一起会很长,操作的时候很影响观感,我们可以手动去除。
首先使用命令查看当前用户名称
bashwhoami
bash#编辑配置文件
vim ~/.zshrc
#在文件最后增加 DEFAULT_USER="xxxxx" 配置
DEFAULT_USER="xxxxx" #里面输入自己想展示的
#退出编辑后执行使配置生效
source ~/.zshrc
再次打开终端姓名和主机名就隐藏掉了。
注意
这里是重点,本人用的是agnoster
、essembeh
这两种主题默认就算修改了我下面的配置也无效需要修改源代码,我已经写好大家替换了内容就好了
目前本人只修改了**
agnoster
、essembeh
这两种主题 源码**
接下来我们对zsh主题进行修改,首先咱们可以使用以下的命令查看所有的oh-my-zsh自带主题
bash#第一种方法查看
ls ~/.oh-my-zsh/themes
#第二种方法
cd ~/.oh-my-zsh/themes
# 接着
ls
agnoster
源码
bash# vim:ft=zsh ts=2 sw=2 sts=2
#
# agnoster's Theme - https://gist.github.com/3712874
# A Powerline-inspired theme for ZSH
#
# # README
#
# In order for this theme to render correctly, you will need a
# [Powerline-patched font](https://github.com/Lokaltog/powerline-fonts).
# Make sure you have a recent version: the code points that Powerline
# uses changed in 2012, and older versions will display incorrectly,
# in confusing ways.
#
# In addition, I recommend the
# [Solarized theme](https://github.com/altercation/solarized/) and, if you're
# using it on Mac OS X, [iTerm 2](https://iterm2.com/) over Terminal.app -
# it has significantly better color fidelity.
#
# If using with "light" variant of the Solarized color schema, set
# SOLARIZED_THEME variable to "light". If you don't specify, we'll assume
# you're using the "dark" variant.
#
# # Goals
#
# The aim of this theme is to only show you *relevant* information. Like most
# prompts, it will only show git information when in a git working directory.
# However, it goes a step further: everything from the current user and
# hostname to whether the last call exited with an error to whether background
# jobs are running in this shell will all be displayed automatically when
# appropriate.
### Segment drawing
# A few utility functions to make it easy and re-usable to draw segmented prompts
CURRENT_BG='NONE'
case ${SOLARIZED_THEME:-dark} in
light) CURRENT_FG='white';;
*) CURRENT_FG='black';;
esac
# Special Powerline characters
() {
local LC_ALL="" LC_CTYPE="en_US.UTF-8"
# NOTE: This segment separator character is correct. In 2012, Powerline changed
# the code points they use for their special characters. This is the new code point.
# If this is not working for you, you probably have an old version of the
# Powerline-patched fonts installed. Download and install the new version.
# Do not submit PRs to change this unless you have reviewed the Powerline code point
# history and have new information.
# This is defined using a Unicode escape sequence so it is unambiguously readable, regardless of
# what font the user is viewing this source code in. Do not replace the
# escape sequence with a single literal character.
# Do not change this! Do not make it '\u2b80'; that is the old, wrong code point.
SEGMENT_SEPARATOR=$'\ue0b0'
}
# Begin a segment
# Takes two arguments, background and foreground. Both can be omitted,
# rendering default background/foreground.
prompt_segment() {
local bg fg
[[ -n $1 ]] && bg="%K{$1}" || bg="%k"
[[ -n $2 ]] && fg="%F{$2}" || fg="%f"
if [[ $CURRENT_BG != 'NONE' && $1 != $CURRENT_BG ]]; then
echo -n " %{$bg%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR%{$fg%} "
else
echo -n "%{$bg%}%{$fg%} "
fi
CURRENT_BG=$1
[[ -n $3 ]] && echo -n $3
}
# End the prompt, closing any open segments
prompt_end() {
if [[ -n $CURRENT_BG ]]; then
echo -n " %{%k%F{$CURRENT_BG}%}$SEGMENT_SEPARATOR"
else
echo -n "%{%k%}"
fi
echo -n "%{%f%}"
CURRENT_BG=''
}
### Prompt components
# Each component will draw itself, and hide itself if no information needs to be shown
# Context: user@hostname (who am I and where am I)
prompt_context() {
if [[ "$USERNAME" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
# prompt_segment black green "%(!.%{%F{yellow}%}.)%n@%m" # 将前景颜色更改为黄色
prompt_segment black green "%(!.%{%F{yellow}%}.)$DEFAULT_USER@%m" # 将前景颜色更改为黄色
fi
}
# Git: branch/detached head, dirty status
prompt_git() {
(( $+commands[git] )) || return
if [[ "$(git config --get oh-my-zsh.hide-status 2>/dev/null)" = 1 ]]; then
return
fi
local PL_BRANCH_CHAR
() {
local LC_ALL="" LC_CTYPE="en_US.UTF-8"
PL_BRANCH_CHAR=$'\ue0a0' #
}
local ref dirty mode repo_path
if [[ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]]; then
repo_path=$(git rev-parse --git-dir 2>/dev/null)
dirty=$(parse_git_dirty)
ref=$(git symbolic-ref HEAD 2> /dev/null) || \
ref="◈ $(git describe --exact-match --tags HEAD 2> /dev/null)" || \
ref="➦ $(git rev-parse --short HEAD 2> /dev/null)"
if [[ -n $dirty ]]; then
prompt_segment yellow black
else
prompt_segment green $CURRENT_FG
fi
local ahead behind
ahead=$(git log --oneline @{upstream}.. 2>/dev/null)
behind=$(git log --oneline ..@{upstream} 2>/dev/null)
if [[ -n "$ahead" ]] && [[ -n "$behind" ]]; then
PL_BRANCH_CHAR=$'\u21c5'
elif [[ -n "$ahead" ]]; then
PL_BRANCH_CHAR=$'\u21b1'
elif [[ -n "$behind" ]]; then
PL_BRANCH_CHAR=$'\u21b0'
fi
if [[ -e "${repo_path}/BISECT_LOG" ]]; then
mode=" <B>"
elif [[ -e "${repo_path}/MERGE_HEAD" ]]; then
mode=" >M<"
elif [[ -e "${repo_path}/rebase" || -e "${repo_path}/rebase-apply" || -e "${repo_path}/rebase-merge" || -e "${repo_path}/../.dotest" ]]; then
mode=" >R>"
fi
setopt promptsubst
autoload -Uz vcs_info
zstyle ':vcs_info:*' enable git
zstyle ':vcs_info:*' get-revision true
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:*' stagedstr '✚'
zstyle ':vcs_info:*' unstagedstr '±'
zstyle ':vcs_info:*' formats ' %u%c'
zstyle ':vcs_info:*' actionformats ' %u%c'
vcs_info
echo -n "${${ref:gs/%/%%}/refs\/heads\//$PL_BRANCH_CHAR }${vcs_info_msg_0_%% }${mode}"
fi
}
prompt_bzr() {
(( $+commands[bzr] )) || return
# Test if bzr repository in directory hierarchy
local dir="$PWD"
while [[ ! -d "$dir/.bzr" ]]; do
[[ "$dir" = "/" ]] && return
dir="${dir:h}"
done
local bzr_status status_mod status_all revision
if bzr_status=$(bzr status 2>&1); then
status_mod=$(echo -n "$bzr_status" | head -n1 | grep "modified" | wc -m)
status_all=$(echo -n "$bzr_status" | head -n1 | wc -m)
revision=${$(bzr log -r-1 --log-format line | cut -d: -f1):gs/%/%%}
if [[ $status_mod -gt 0 ]] ; then
prompt_segment yellow black "bzr@$revision ✚"
else
if [[ $status_all -gt 0 ]] ; then
prompt_segment yellow black "bzr@$revision"
else
prompt_segment green black "bzr@$revision"
fi
fi
fi
}
prompt_hg() {
(( $+commands[hg] )) || return
local rev st branch
if $(hg id >/dev/null 2>&1); then
if $(hg prompt >/dev/null 2>&1); then
if [[ $(hg prompt "{status|unknown}") = "?" ]]; then
# if files are not added
prompt_segment red white
st='±'
elif [[ -n $(hg prompt "{status|modified}") ]]; then
# if any modification
prompt_segment yellow black
st='±'
else
# if working copy is clean
prompt_segment green $CURRENT_FG
fi
echo -n ${$(hg prompt "☿ {rev}@{branch}"):gs/%/%%} $st
else
st=""
rev=$(hg id -n 2>/dev/null | sed 's/[^-0-9]//g')
branch=$(hg id -b 2>/dev/null)
if `hg st | grep -q "^\?"`; then
prompt_segment red black
st='±'
elif `hg st | grep -q "^[MA]"`; then
prompt_segment yellow black
st='±'
else
prompt_segment green $CURRENT_FG
fi
echo -n "☿ ${rev:gs/%/%%}@${branch:gs/%/%%}" $st
fi
fi
}
# Dir: current working directory
prompt_dir() {
local home_dir="${HOME}"
local current_dir="${PWD}"
if [[ "${current_dir}" = "${home_dir}" ]]; then
# 当前目录是主目录
prompt_segment blue $CURRENT_FG '%~'
else
# 当前目录不是主目录,只显示 "~" 表示主目录
# prompt_segment blue $CURRENT_FG '%~'
prompt_segment blue $CURRENT_FG '%1~'
fi
}
# Virtualenv: current working virtualenv
prompt_virtualenv() {
if [[ -n "$VIRTUAL_ENV" && -n "$VIRTUAL_ENV_DISABLE_PROMPT" ]]; then
prompt_segment blue black "(${VIRTUAL_ENV:t:gs/%/%%})"
fi
}
# Status:
# - was there an error
# - am I root
# - are there background jobs?
prompt_status() {
local -a symbols
[[ $RETVAL -ne 0 ]] && symbols+="%{%F{red}%}✘"
[[ $UID -eq 0 ]] && symbols+="%{%F{yellow}%}⚡"
[[ $(jobs -l | wc -l) -gt 0 ]] && symbols+="%{%F{cyan}%}⚙"
[[ -n "$symbols" ]] && prompt_segment black default "$symbols"
}
#AWS Profile:
# - display current AWS_PROFILE name
# - displays yellow on red if profile name contains 'production' or
# ends in '-prod'
# - displays black on green otherwise
prompt_aws() {
[[ -z "$AWS_PROFILE" || "$SHOW_AWS_PROMPT" = false ]] && return
case "$AWS_PROFILE" in
*-prod|*production*) prompt_segment red yellow "AWS: ${AWS_PROFILE:gs/%/%%}" ;;
*) prompt_segment green black "AWS: ${AWS_PROFILE:gs/%/%%}" ;;
esac
}
## Main prompt
build_prompt() {
RETVAL=$?
prompt_status
prompt_virtualenv
prompt_aws
prompt_context
prompt_dir
prompt_git
prompt_bzr
prompt_hg
prompt_end
}
PROMPT='%{%f%b%k%}$(build_prompt) '
essembeh
源码
bash# My custom theme:
# - single line
# - quite simple by default: user@host:$PWD
# - green for local shell as non root
# - red for ssh shell as non root
# - magenta for root sessions
# - prefix with remote address for ssh shells
# - prefix to detect docker containers or chroot
# - git plugin to display current branch and status
# git plugin
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[cyan]%}("
ZSH_THEME_GIT_PROMPT_SUFFIX=") %{$reset_color%}"
ZSH_THEME_GIT_PROMPT_UNTRACKED="%%"
ZSH_THEME_GIT_PROMPT_ADDED="+"
ZSH_THEME_GIT_PROMPT_MODIFIED="*"
ZSH_THEME_GIT_PROMPT_RENAMED="~"
ZSH_THEME_GIT_PROMPT_DELETED="!"
ZSH_THEME_GIT_PROMPT_UNMERGED="?"
function zsh_essembeh_gitstatus {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
GIT_STATUS=$(git_prompt_status)
if [[ -n $GIT_STATUS ]]; then
GIT_STATUS=" $GIT_STATUS"
fi
echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$GIT_STATUS$ZSH_THEME_GIT_PROMPT_SUFFIX"
}
# by default, use green for user@host and no prefix
local ZSH_ESSEMBEH_COLOR="green"
local ZSH_ESSEMBEH_PREFIX=""
if [[ -n "$SSH_CONNECTION" ]]; then
# display the source address if connected via ssh
ZSH_ESSEMBEH_PREFIX="%{$fg[yellow]%}[$(echo $SSH_CONNECTION | awk '{print $1}')]%{$reset_color%} "
# use red color to highlight a remote connection
ZSH_ESSEMBEH_COLOR="red"
elif [[ -r /etc/debian_chroot ]]; then
# prefix prompt in case of chroot
ZSH_ESSEMBEH_PREFIX="%{$fg[yellow]%}[chroot:$(cat /etc/debian_chroot)]%{$reset_color%} "
elif [[ -r /.dockerenv ]]; then
# also prefix prompt inside a docker container
ZSH_ESSEMBEH_PREFIX="%{$fg[yellow]%}[docker]%{$reset_color%} "
fi
if [[ $UID = 0 ]]; then
# always use magenta for root sessions, even in ssh
ZSH_ESSEMBEH_COLOR="magenta"
fi
# PROMPT='${ZSH_ESSEMBEH_PREFIX}%{$fg[$ZSH_ESSEMBEH_COLOR]%}%n@%M%{$reset_color%}:%{%B$fg[yellow]%}%~%{$reset_color%b%} $(zsh_essembeh_gitstatus)%(!.#.$) '
# PROMPT='${ZSH_ESSEMBEH_PREFIX}%{$fg[$ZSH_ESSEMBEH_COLOR]%}$DEFAULT_USER@%M%{$reset_color%}:%{%B$fg[yellow]%}%~%{$reset_color%b%} $(zsh_essembeh_gitstatus)%(!.#.$) '
PROMPT='${ZSH_ESSEMBEH_PREFIX}%{$fg[$ZSH_ESSEMBEH_COLOR]%}$DEFAULT_USER@%M%{$reset_color%}: $(zsh_essembeh_gitstatus)%(!.#.$)'
# RPROMPT="%(?..%{$fg[red]%}%?%{$reset_color%})"
最后就完美了,也不会打开一个项目出现特别长的项目名称目录、同样DEFAULT_USER
也生效了
iTerm2 提供了不少的 Status bar,开启后我们可以在终端的最上方非常方便的实时查看本机的一些信息。
打开iTerm2,打开Preferences配置界面,Profiles -> session-> 勾选 Status bar enable-> configure Status bar,选择自己想要的展示内容即可。
iterm提供了三种光标可供选择:_、|、[]。
打开iTerm2,打开Preferences配置界面,Profiles -> text-> cursor,选择自己想要的光标即可。
打开iTerm2,打开Preferences配置界面,Profiles -> Window,根据自己的需求设置窗口透明度、背景图片、行列数以及风格等。
设置好后的效果如下:
打开iTerm2,打开Preferences配置界面,Profiles -> General ,根据自己的需求设置Badge,点击edit按钮调整Badge位置和大小,Title和Icon选项是设置标签页标题和图标的,博主习惯性采用图片中的设置,各位看官可以根据自己的需求灵活设置。
设置效果如下:
标签配色默认为黑色,不能与操作页面保持统一
打开iTerm2,打开Preferences配置界面,Appearence -> General,将 Theme 改为 Minimal
博主以连接腾讯云服务器为例:
bash# 首先进入公钥目录下按照如下命令创建sh脚本
cd ~/.ssh
#创建myserver.sh文件
touch myserver.sh
#编辑myserver.sh文件
vim myserver.sh
键盘输入i编辑文件,插入以下内容:
文件中变量解释: set host :
服务器IP地址
set user:服务器用户名
set password:服务器密码
set port:端口号
bashset host 117.20.172.133
set user root
set password 1521506229818ldl
set port 22
#set timeout -1
spawn ssh $user@$host
expect "*assword:*"
send "$password\r"
interact
expect eof
插入完成后键盘esc 然后输入
退出,接下来给文件赋权bashchmod 777 myserver.sh
打开iTerm2,打开Preferences配置界面,Profiles -> general,左下角点击+号,新建profile,参考下面图片在对应位置输入内容即可。
设置好之后打开iTerm2,点击profiles,点击前面自己新增的连接远程服务器的profile的名字
首次连接需要输入一次服务器密码,之后再连接就免密码登陆了
打开iTerm2,打开Preferences配置界面,Profiles -> Terminal,根须需求进行修改,如果想不限制行数可以勾选Unlimited scrollback
本文作者:LiuXueChao
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!