Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mac - iTerm 基础配置 #70

Open
Qingquan-Li opened this issue Oct 26, 2017 · 0 comments
Open

Mac - iTerm 基础配置 #70

Qingquan-Li opened this issue Oct 26, 2017 · 0 comments
Labels

Comments

@Qingquan-Li
Copy link
Owner

Qingquan-Li commented Oct 26, 2017

设置高亮模式

iTerm 默认不会高亮显示

  1. 前往 ~/.bash_profile 文件
  2. 加入以下代码:
#enables colorin the terminal bash shell export
export CLICOLOR=1

#sets up thecolor scheme for list export
export LSCOLORS=GxFxCxDxBxegedabagaced

#sets up theprompt color (currently a green similar to linux terminal)
export PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
  1. Preferences -> Profiles -> Terminal -> Terminal Emulation -> Report Terminal Type ,选择 xterm-256color
  2. 重启 iTerm2 ,选择配色方案: Preferences -> Profiles -> Colors -> Load Presets

highlighting-auto



安装其它主题

以安装 Dracula 为例: https://draculatheme.com/iterm/

importdracula



使用 zsh

  • Zsh 和 Bash 一样,是一种 Unix shell ,使用 cat /etc/shells 命令查看已经安装的 shell
  • Zsh有强大的自动补全参数、自定义配置功能… 快速上手 Zsh : https://github.com/robbyrussell/oh-my-zsh
  • Mac 预装 zsh

安装 iTerm 后,使用一下命令把 bash 切换成 zsh ,重启 iTerm (或新建一个窗口)后即可使用 zsh :

chsh -s /bin/zsh

zsh 切换回 bash ,同理:

chsh -s /bin/bash


安装 oh-my-zsh

zsh 配置比较复杂, oh-my-zsh 作为一个开源项目出现,让 zsh 的配置降到 0 门槛,并且完全兼容 bash

  1. 下载: git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
  2. 替换 zshrc : cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
  3. bash 切换成 zsh : chsh -s /bin/zsh
  4. zsh 切换成 bash:chsh -s /bin/bash

注:另一种安装方式:wget 自动安装:
wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | sh
安装 oh-my-zsh 时,它自动读取你的环境变量并且自动帮 zsh 进行设置

oh-my-zsh



on-my-zsh 主题之绝对路径

oh my zsh 提供了数十种主题,相关文件在 ~/.oh-my-zsh/themes 目录下,默认主题是 robbyrussell 。修改默认主题,显示绝对路径:把 c 改为 dc 表示当前目录,d 表示绝对路径,另外在末尾增加了一个

# PROMPT='${ret_status} %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)'
PROMPT='${ret_status} %{$fg[cyan]%}%d%{$reset_color%} $(git_prompt_info)> '

oh-my-zsh_absolute-path



on-my-zsh 插件

一、安装自带插件

oh my zsh 开源项目提供了完善的插件体系,相关的文件在 ~/.oh-my-zsh/plugins 目录下,默认提供了100多种。插件在 .zshrc 里配置,找到 plugins 关键字,添加需要的插件即可,插件之间用空格隔开,系统默认加载 git ,如下:

  1. plugins=(git osx python)
  2. 命令行中,source 一下使配置生效: source ~/.zshrc

oh-my-zsh_plugins


二、安装 zsh-syntax-highlighting 语法高亮插件

https://github.com/zsh-users/zsh-syntax-highlighting

  1. 自动下载并安装: brew install zsh-syntax-highlighting
  2. 在 ~/.zshrc 文件中添加语句: source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh (因为 zsh-syntax-highlighting 下载在 /usr/local/share/ 目录中,并不是在 oh-my-zsh 自带的 ~/.oh-my-zsh/plugins 插件目录中,所以使用以上的插入语句,而不是 plugins=(git osx python zsh-syntax-highlighting)
    oh-my-zsh_zsh-syntax-highlighting_1
  3. 命令行中,source 一下使配置生效: source ~/.zshrc

oh-my-zsh_zsh-syntax-highlighting_2


三、安装 autojump 快速切换路径插件(方法同上)

  1. 自动下载并安装: brew install autojump
  2. 在 ~/.zshrc 文件中添加语句: [ -f /usr/local/etc/profile.d/autojump.sh ] && . /usr/local/etc/profile.d/autojump.sh
    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
  3. 命令行中,source 一下使配置生效: source ~/.zshrc

注:虽然 oh-my-zsh 提供了很多插件,但大量的插件会拖慢打开的速度,因此只安装常用的就好了。


参考:MacTalk - 终极 shell



附:iTerm 保持 ssh 连接不断线

参考:

在本地环境中编辑或创建 ~/.ssh/config 文件,增加:

Host *
ServerAliveInterval 300
ServerAliveCountMax 6

300 是发给服务端心跳的间隔,单位是秒,根据你自己的服务器情况设置。
6 是最多发送的次数,如果想一直保持连接,本项可以不写。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant