DEV Community

hikerpig
hikerpig

Posted on • Originally published at hikerpig.cn on

使用 zimfw 作为 zsh 配置框架

之前使用 oh-my-zsh 的自带 git/nvm 等插件有时候有性能问题,同时据说其框架本身相比其他一些主打速度的配置框架(prezto/zimfw 等)也会慢一点。

稍微折腾了一下,使用 zimfw 作为 zsh 配置框架,它在速度和可配置性间达到了很好的平衡。

个人切换后,试了下跑 zprof,启动时间只有原先的一半,度量方式参考 Profiling zsh startup time

插件加载

用上自带的模块zsh-users里一些优秀的插件,就已经有很好的表现,其中 zsh-users/zsh-autosuggestions 和 zsh-users/zsh-syntax-highlighting 能让 zsh 也有类似于 fish 一样友好的代码高亮反馈和输入自动补全功能。zimfw 比较友好的一点就在于默认配置(使用其提供的安装脚本)里给出的组合就已经很棒了。

添加插件的方式与 oh-my-zsh 不太一样,后者需要把插件添加到指定的 plugins 目录(一般为 clone repo 或者拷贝文件),然后在 .zshrc 文件里 plugins=() 数组里添加插件名。

而 zimfw 的方式则稍微方便一点,除了类似后者的方式外,还可以不用手动操作目录而是在 .zimrc 文件中添加模块名(一般为 github 上的 user/repo 名),可在 awesome-zsh-plugins 里寻找合适插件,多数与配置框架无关(可以不局限在 oh-my-zsh 提供的插件目录里)。

修改配置文件后,使用命令 zimfw install 下载并编译插件(会使用 zsh builtin 的 zcompile.zsh 文件编译为 .zwc 字节码,提高下次加载的速度),打开新 shell 时新插件生效。

外观和主题

zimfw 的主题远不如 oh-my-zsh 丰富,自己的 gallery 里都是偏向极简的风格,不过我们可以自己找一些成熟的主题 powerlevel10k 使用,带有问答式的新手配置指导,功能丰富,推荐使用。

一些配置

~/.zimrc

# Start configuration added by Zim install {{{
# -------
# Modules
# -------
# Sets sane Zsh built-in environment options.
zmodule environment
# Applies correct bindkeys for input events.
zmodule input
# Sets a custom terminal title.
zmodule termtitle
# Utility aliases and functions. Adds colour to ls, grep and less.
zmodule utility
zmodule directory

#
# Prompt
#
# Exposes git repository status information to prompts.
zmodule git-info

# Theme
zmodule romkatv/powerlevel10k

# Additional completion definitions for Zsh.
zmodule zsh-users/zsh-completions
# Enables and configures smart and extensive tab completion.
# completion must be sourced after zsh-users/zsh-completions
zmodule completion
# Fish-like autosuggestions for Zsh.
zmodule zsh-users/zsh-autosuggestions
# Fish-like syntax highlighting for Zsh.
# zsh-users/zsh-syntax-highlighting must be sourced after completion
zmodule zsh-users/zsh-syntax-highlighting
# Fish-like history search (up arrow) for Zsh.
# zsh-users/zsh-history-substring-search must be sourced after zsh-users/zsh-syntax-highlighting
zmodule zsh-users/zsh-history-substring-search
# }}} End configuration added by Zim install

# Custom 个人推荐的插件
zmodule DarrinTisdale/zsh-aliases-exa
zmodule zsh-users/zaw
zmodule wookayin/fzf-fasd
Enter fullscreen mode Exit fullscreen mode

介绍一些程序和插件:

参考文章

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay