ohmyzsh配置_Mac

🧰 第一步:安装必要工具

✅ 1. 安装 Homebrew(如果未安装)

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

✅ 2. 安装最新版 Zsh(可选,但推荐)

macOS 自带 zsh,但可以用 Homebrew 安装新版本:

brew install zsh

✅ 3. 安装 Oh My Zsh

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

安装后会自动生成 ~/.zshrc 配置文件。


🎨 第二步:美化终端和增强体验

✅ 1. 安装 Powerlevel10k 主题(强烈推荐)

brew install romkatv/powerlevel10k/powerlevel10k

然后在 ~/.zshrc 文件中设置:

ZSH_THEME="powerlevel10k/powerlevel10k"

保存后运行:

source ~/.zshrc

首次运行会触发自动配置向导。


🔌 第三步:安装实用插件

✅ 插件推荐安装列表

brew install zsh-autosuggestions
brew install zsh-syntax-highlighting
brew install autojump

✅ 修改 .zshrc 插件配置:

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

# 启用插件(必须在 plugins 后添加 source)
source /opt/homebrew/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
source /opt/homebrew/share/zsh-autosuggestions/zsh-autosuggestions.zsh
[ -f /opt/homebrew/etc/profile.d/autojump.sh ] && . /opt/homebrew/etc/profile.d/autojump.sh
# 插件启用
plugins=(git zsh-autosuggestions zsh-syntax-highlighting)
# 启用补全系统
autoload -Uz compinit && compinit

⚠️ 注意路径,如果你是 Intel Mac 用户,/opt/homebrew 可能需要换成 /usr/local


🧩 第四步:实用别名和自定义函数(可选)

.zshrc 文件底部加入:

alias ll="ls -lah"
alias gs="git status"
alias gl="git log --oneline --graph --decorate"
alias c="clear"

🔁 第五步:刷新配置文件并生效

source ~/.zshrc

或者关闭 Terminal 再重新打开。


🎁 Bonus:你的终端工具推荐(更 Typora-like)


🧩 整体结构 .zshrc 示例

export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="powerlevel10k/powerlevel10k"

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

source $ZSH/oh-my-zsh.sh

# 插件手动 source(Homebrew 安装路径)
source /opt/homebrew/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
source /opt/homebrew/share/zsh-autosuggestions/zsh-autosuggestions.zsh
[ -f /opt/homebrew/etc/profile.d/autojump.sh ] && . /opt/homebrew/etc/profile.d/autojump.sh

# Alias 快捷命令
alias ll="ls -lah"
alias gs="git status"
alias gl="git log --oneline --graph --decorate"
alias c="clear"

posted @ 2025-05-25 00:59  tomorgen  阅读(394)  评论(0)    收藏  举报