iTerm2教程|如何使用iTerm2对环境进行重新配色和美化?

这是一款轻巧但功能强大的Mac终端仿真软件,是可替代Apple终端和iTerm的继任者。那么如何使用iTerm2对环境进行重新配置?今天macw小编就带了iTerm2教程——如何使用iTerm2对环境进行重新配色和美化?
下载安装iTerm2
首先,下载iTerm2来替换默认终端。在这里插入图片描述(可选)迁移配置
因为我之前也是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效果:在这里插入图片描述显示的内容也可以自己调节:在这里插入图片描述设置zsh主题
配置主题:
只需要修改 .zshrc 文件中的 ZSH_THEME=“xx” 属性即可。
我目前使用的主题是:spaceship
按照github项目说明中的方法配置即可,或者参考本文下面的主题配置
前提:
安装了zsh
安装了powerline字体
然后把iTerm的字体设置为powerline,包括Font和Non-ASCII Font在这里插入图片描述下载主题文件:
git clone https://github.com/denysdovhan/spaceship-prompt.git “$ZSH_CUSTOM/themes/spaceship-prompt” --depth=1
创建软连接

ln -s “ Z S H C U S T O M / t h e m e s / s p a c e s h i p − p r o m p t / s p a c e s h i p . z s h − t h e m e " " ZSH_CUSTOM/themes/spaceship-prompt/spaceship.zsh-theme" " ZSHCUSTOM/themes/spaceshipprompt/spaceship.zshtheme""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命令行,提供了主题配置,插件机制,大大提高了可玩(用)性。提升使用效率还能使人愉快
输入如下命令:
curl方式
sh -c “ ( c u r l − f s S L h t t p s : / / r a w . g i t h u b u s e r c o n t e n t . c o m / o h m y z s h / o h m y z s h / m a s t e r / t o o l s / i n s t a l l . s h ) " 或 者 使 用 w g e t : s h − c " (curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" 或者使用wget: sh -c " (curlfsSLhttps://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"使wgetshc"(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 了
安装方法:
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 以上就是MacW小编为大家带来的“iTerm2教程|如何使用iTerm2对环境进行重新配色和美化?”,本文关键词:“iTerm2教程,iTerm2使用,终端软件”。