惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
博客园 - 司徒正美
Last Week in AI
Last Week in AI
博客园 - 聂微东
Jina AI
Jina AI
月光博客
月光博客
爱范儿
爱范儿
美团技术团队
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Hugging Face - Blog
Hugging Face - Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 叶小钗
T
Tailwind CSS Blog
博客园 - 【当耐特】
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Apple Machine Learning Research
Apple Machine Learning Research
有赞技术团队
有赞技术团队
罗磊的独立博客
小众软件
小众软件
雷峰网
雷峰网
IT之家
IT之家
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Visual Studio Blog

少数派

派早报:Google 发布 Fitbit Air 等 - 少数派 「新人报到」確認需求,再開始 - 少数派 从 SOLO 独立开发者社区,我看到了越来越多开发者开始做自己的产品 - 少数派 我怎么管理那些"不常做,但总会忘"的生活事项 - 少数派 人形机器人量产元年,数据才是具身智能的“生死线” - 少数派 BuhoLaunchpad 高度还原 Mac 启动台:开发历程与思考 - 少数派 五年陪伴依然不舍,DIY 换壳后让罗技 MX Master 3 继续服役 - 少数派 新玩意 240|少数派的编辑们最近买了啥? - 少数派 一日一技|为什么你应该关闭 iOS 的键盘声音 - 少数派 我做了个插件和 Skills,一键提取任何网站的设计规范 Design.md - 少数派 住在三四线城市的你,该开始录播客了 - 少数派 甘南秘境,大白高国 - 少数派 AI的审美:谁让把我变成川内倫子 - 少数派 返工怎能不烦恼,打工人片单总有一部是你的「嘴替」 - 少数派 为了让「上厕所」更健康,我做了一个小工具 - 少数派 AI + Skill,能够让生成的文章去除 AI 味吗? - 少数派 新玩意|韶音OpenDots ONE 耳夹式耳机 - 少数派 《美满》| 在每一个春天的晚上相爱(362) - 少数派 新玩意|优篮子 PS01 MagSnap 磁吸支架 - 少数派 自我整合手记 | 我开始早睡了:用稳定规则,为自由托底 - 少数派 用龙虾(OpenClaw)两个多月,我最深的12个体会 - 少数派 听歌时间到,12 张你可能错过的 2025 华语乐坛好专辑 - 少数派 承诺能追吗 - 少数派 macOS 26启动台没了? 我做了个不一样的App启动器 - Keboard - 少数派 《四海为家的人》| INTJ对话INTJ(361) - 少数派 你发过的那些黑历史,是时候一次清干净了 - 少数派 新玩意:安安静静玩,越玩越专注:计客密码机 - 少数派 iPad 用户首次体验 Android 平板:vivo Pad6 Pro - 少数派 数据逻辑强 - 少数派 极北行+ | 一路向北,探访日本至北之地 | 001 - 少数派
iTerm2 配置和美化 - 少数派
2020-10-21 · via 少数派

前言

因为换了新电脑,软件和环境需要重新配置,就关于iTerm2的配置和美化整理一份文章出来,方便自己之后的工作,也给大家提供点参考,有错误欢迎大家指出,如果有好用的插件或好看的配色也欢迎分享😁。


首先,下载iTerm2来替换默认终端。

https://iterm2.com/

什么是iTerm2?

iTerm2 is a replacement for Terminal and the successor to iTerm. It works on Macs with macOS 10.12 or newer. iTerm2 brings the terminal into the modern age with features you never knew you always wanted.

iTerm2是默认终端的替代品,也是目前Mac系统下最好用的终端工具,集颜值和效率于一身。

迁移配置(可选)

因为我之前也是Mac平台,所以有一些配置可以在ITerm里导出,其实重新配置也都一样,没有什么影响。

在原电脑上的iterm导出配置:

导出配置

然后在新电脑导入:

如上图 import JSON Profiles,然后设置为默认配置。

导入并使用

调整Status Bar

 将 iTerm2 自带 theme 修改为 Minimal ( Preferences-Appearance-General-Theme ) 以达到顶栏沉浸式的效果

可以在Profiles选项卡,Session页面最底部看到开启选项。Status bar enabled 选项,勾选上即可打开。点击右边的 Configure Status Bar 按钮可设置显示的内容。

可以看到能显示的内容非常多,把上方要显示的内容拖动到下方 Active Components 区域即添加。

在Preference页面中点击Appearance选项卡,可以设置Status bar的位置,修改 Status bar location,我这里改到Bottom底部。

设置位置

Status bar效果:

显示的内容也可以自己调节:

Status bar调节

更改配色(可选)

我比较喜欢 Dracula 配色方案,包括VS Code使用的都是这个配色方案。

https://draculatheme.com/iterm/

解压后更换 Preferences-Profiles-Color-Color Presets-Import

设置zsh主题

配置主题:

只需要修改 .zshrc 文件中的 ZSH_THEME="xx" 属性即可。

我目前使用的主题是:spaceship

按照github项目说明中的方法配置即可,或者参考本文下面的主题配置

前提:

安装了zsh

安装了powerline字体

安装方法参考:https://github.com/powerline/fonts

然后把iTerm的字体设置为powerline,包括Font和Non-ASCII Font

设置字体

下载主题文件:

git clone https://github.com/denysdovhan/spaceship-prompt.git "$ZSH_CUSTOM/themes/spaceship-prompt" --depth=1

创建软连接

ln -s "$ZSH_CUSTOM/themes/spaceship-prompt/spaceship.zsh-theme" "$ZSH_CUSTOM/themes/spaceship.zsh-theme"

修改zsh配置

vim ~/.zshrc

修改:

ZSH_THEME="spaceship"

生效:

source ~/.zshrc

然后就是主题的一些配置,配置说明参考这个文件:

https://github.com/denysdovhan/spaceship-prompt/blob/master/docs/Options.md

具体配置显示哪些内容,根据文档在  ./zshrc 中添加就好。这里说一下我的配置:

PS:颜色数值参考这个https://upload.wikimedia.org/wikipedia/commons/1/15/Xterm_256color_chart.svg

我的配置

设置显示时间

SPACESHIP_TIME_SHOW="true"

设置显示用户名,并改用户名颜色为猛男粉

SPACESHIP_USER_SHOW="always"

SPACESHIP_USER_COLOR="212"

主题对应地址:

https://github.com/denysdovhan/spaceship-prompt

设置Oh-My-Zsh

什么是Oh-My-Zsh?

Oh My Zsh是一款社区驱动的命令行工具,它基于zsh命令行,提供了主题配置,插件机制,大大提高了可玩(用)性。提升使用效率还能使人愉快hhh

Oh My Zsh is a delightful, open source, community-driven framework for managing your Zsh configuration. It comes bundled with thousands of helpful functions, helpers, plugins, themes, and a few things that make you shout...

网站:https://ohmyz.sh/

输入如下命令:

curl方式

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

或者使用wget:

sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"

配置Oh-My-Zsh

配置命令自动提示

关于插件的配置,如果要看目前安装了哪些插件,可以在.zshrc中搜索plugins关键字,获得如下,也是我老电脑中的配置内容:

plugins=(
  git
  autojump
  zsh-autosuggestion
  zsh-syntax-highlighting
)

关于命令提示

当我们输入命令过程中,终端会自动提示你接下来可能要输入的命令,这时按 → 便可输出这些命令,非常方便。

效果可参考GitHub项目说明中的视频

项目地址:https://github.com/zsh-users/zsh-autosuggestions

1、克隆项目到本地 $ZSH_CUSTOM/plugins  路径下 `默认是  ·~/.oh-my-zsh/custom/plugins

git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

2、编辑 `~/.zshrc` 配置文件,添加到plugins列表中

plugins=(zsh-autosuggestion)

3、新开一个终端窗口查看效果

自动提示

如果最后看不到提示的效果可能是颜色配置问题,参考GitHub项目说明中的修改方法去修改配置

配置语法高亮显示

项目地址:
https://github.com/zsh-users/zsh-syntax-highlighting

安装方法:

推荐使用HomeBrew进行安装:
1、brew安装

brew install zsh-syntax-highlighting

brew的项目地址 https://brew.sh/

2、~/.zshrc 尾部,插入一行:

source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

vim中 直接使用 shift+g 可以跳转的最后一行

3、生效配置

source ~/.zshrc

❗️不过这时产生了一些警告信息:

➜ source ~/.zshrc

[oh-my-zsh] Insecure completion-dependent directories detected:

drwxrwxr-x  3 lanvnal  admin   96  9 22 01:51 /usr/local/share/zsh

drwxrwxr-x  4 lanvnal  admin  128  9 22 01:53 /usr/local/share/zsh/site-functions



[oh-my-zsh] For safety, we will not load completions from these directories until

[oh-my-zsh] you fix their permissions and ownership and restart zsh.

[oh-my-zsh] See the above list for directories with group or other writability.



[oh-my-zsh] To fix your permissions you can do so by disabling

[oh-my-zsh] the write permission of "group" and "others" and making sure that the

[oh-my-zsh] owner of these directories is either root or your current user.

[oh-my-zsh] The following command may help:

[oh-my-zsh]     compaudit | xargs chmod g-w,o-w



[oh-my-zsh] If the above didn't help or you want to skip the verification of

[oh-my-zsh] insecure directories you can set the variable ZSH_DISABLE_COMPFIX to

两种解决方法:

1、按照安装提示去修改对应目录的权限:

chmod 755 /usr/local/share/zsh

chmod 755 /usr/local/share/zsh/site-functions

2、~/.zshrc  这个文件中新增  ZSH_DISABLE_COMPFIX=true 即可。

配置autojump

效果:

 实现目录间快速跳转,想去哪个目录直接 j + 目录名(甚至不用输全),不用在频繁的 cd 了

项目地址:https://github.com/wting/autojump

安装方法:

1、brew安装

brew install autojump

2、修改 `~/.zshrc` 文件,添加到plugins配置列表并在尾部追加如下内容:

[ -f /usr/local/etc/profile.d/autojump.sh ] && . /usr/local/etc/profile.d/autojump.sh

plugins中别忘了添加上autojump:

plugins=(

 git

 zsh-autosuggestion

 autojump

)

然后source使他生效

PS:在brew安装完会有提示输出,按照提示来配置就好:

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

If you use the Fish shell then add the following line to your ~/.config/fish/config.fish:
  [ -f /usr/local/share/autojump/autojump.fish ]; and source /usr/local/share/autojump/autojump.fish

zsh completions have been installed to:
  /usr/local/share/zsh/site-functions

总结

这是目前我比较喜欢的配色和美化方案,在配置过程中也踩了一些坑,遇到了一些问题,就总结于此文,当然,配色和插件都有自己的偏好,欢迎大家留言交流😁