简介

对于程序猿来说,你或多或少地都会接触到命令行,甚至很多程序员只在终端下就能完成大部分工作,所以一个易用又漂亮的终端配置教程来了。
02-iTerm2 + OhMyZsh - 图1

iTerm2

安装

iTeram2《官网》

  1. brew install iterm2

配色

官网:《GitHub》《Solarized Dark Higher Contrast》
安装:将配色方案的内容复制并保存为本地文件(SolarizedDarkHigherContrast.itermcolors),然后双击安装。
设置:iTerm2 ==> Preferences ==> Profiles ==> Colors ==> Colors Presets ==> SolarizedDarkHigherContrast

透明度

设置:

  • iTerm2 ==> Preferences ==> Profiles ==> Window ==> Transparency ==> 15
  • iTerm2 ==> Preferences ==> Profiles ==> Window ==> Transparency ==> Keep backaground colors opaque

    字体

    官网:《链接》
    1. brew tap homebrew/cask-fonts
    2. brew install --cask font-hack-nerd-font

设置:

  • iTerm2 ==> Preferences ==> Profiles ==> Text ==> Font ==> Hack Nerd Font Mono
  • iTerm2 ==> Preferences ==> Profiles ==> Text ==> Font ==> Regular
  • iTerm2 ==> Preferences ==> Profiles ==> Text ==> Font ==> 14

    背景图片

    设置:iTerm2 ==> Preferences ==> Profiles ==> Window ==> Background Image ==> Enabled,选择自己喜欢的背景图即可。
    推荐背景图:《地图》《鬼刀》

    回滚缓冲区

    回滚缓冲区:无限缓冲区,防止执行命令的输出过多,导致无法查询执行结果。
    设置:iTerm2 ==> Preferences ==> Profiles ==> Terminal ==> Scrollback Buffer ==> Unlimited scrollback

    克隆会话

    避免重复输入登录堡垒机的口令:iTerm2 ==> Preferences ==> General ==> Working Directory ==> Reuse previous sessions’s directory
    配置SSH
    1. mkdir -p ~/.ssh
    2. vim ~/.ssh/config
    ```properties Host * User root Port 22 ControlMaster auto ControlPath ~/.ssh/%C ServerAliveInterval 60 ServerAliveCountMax 10 StrictHostKeyChecking no UserKnownHostsFile /dev/null

Host XBlog Hostname xiaocoder.com

Host XK8S Hostname 47.108.28.233

Host SS Hostname 139.198.121.164

Host agumon.com Hostname github.com User git IdentityFile ~/.ssh/agumon_id_rsa

  1. <a name="d24a4395"></a>
  2. ### 凿壁偷光
  3. ```bash
  4. # 需要客户端
  5. export all_proxy="socks5://127.0.0.1:1086"
  1. curl https://api.myip.com
  1. unset all_proxy

OhMyZsh

安装

MacOS一般自带了Zsh,无需额外安装,修改默认的ShellZsh

  1. chsh -s /bin/zsh

OhMyZsh:轻松配置Zsh,快速提高工作效率。

  1. # GitHub
  2. sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
  1. # Gitee 推荐国内用户使用
  2. sh -c "$(curl -fsSL https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh)"

主题

官网:《链接》
克隆主题仓库到OhMyZsh的用户自定义主题目录中:

  1. # GitHub
  2. git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/themes/powerlevel10k
  1. # Gitee 推荐国内用户使用
  2. git clone --depth=1 https://gitee.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/themes/powerlevel10k

设置变量后,需重启终端:

  1. sed -i "" 's@^ZSH_THEME=.*@ZSH_THEME="powerlevel10k/powerlevel10k"@g' ~/.zshrc

配置主题:

  1. # 在终端执行交互式命令进行配置
  2. p10k configure
  3. # Install Meslo Nerd Font?(下载字体):No
  4. # Does this look like a diamond (rotated square)?(钻石图标):Yes
  5. # Does this look like a lock?(锁图标):Yes
  6. # Does this look like a Debian logo (swirl/spiral)?(Debian Logo):Yes
  7. # Do all these icons fit between the crosses?:Yes
  8. # Prompt Style(提示样式):Rainbow
  9. # Character Set(字符集):Unicode
  10. # Show current time?(显示当前时间):24-hour format
  11. # Prompt Separators(提示分隔符):Angled
  12. # Prompt Heads(提示头部):Sharp
  13. # Prompt Tails(提示尾部): Blurred
  14. # Prompt Height(提示高度):One line
  15. # Prompt Spacing(提示间距):Compact
  16. # Icons(图标):Many icons
  17. # Prompt Flow(提示流): Concise
  18. # Enable Transient Prompt(瞬时提示): No
  19. # Instant Prompt Mode(即时提醒):Verbose
  20. # 是否覆盖已存在的配置文件:Yes
  21. # 是否应用配置文件:Yes

插件

设置~/.zshrc中的变量:

  1. plugins=(
  2. git
  3. colored-man-pages
  4. colorize
  5. github
  6. brew
  7. macos
  8. autojump
  9. zsh-autosuggestions
  10. zsh-syntax-highlighting
  11. )

autojump:可以用于直达常用目录。

  1. brew install autojump

zsh-autosuggestions:补全历史输入的命令,用方向键->即可补全。

  1. # GitHub
  2. git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
  3. # Gitee 推荐国内用户使用
  4. git clone https://gitee.com/pocmon/zsh-autosuggestions.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

zsh-syntax-highlighting:语法高亮显示。

  1. # GitHub
  2. git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
  3. # Gitee 推荐国内用户使用
  4. git clone https://gitee.com/lightnear/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting