blog
blog copied to clipboard
macOS 11 手动配置 Terminal (zsh)
- macOS 11 Terminal 默认使用 zsh 。
- 此处不使用 oh-my-zsh 配置,而是选择手动配置:highlighting 高亮和 git分支名显示。
在 ~/.zshrc
文件下新增以下配置:
# $ brew install zsh-syntax-highlighting
# To activate the syntax highlighting, add the following at the end of your .zshrc:
source /opt/homebrew/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
# /private/etc/zshrc 中默认配置的命令提示符(Default prompt)如下:
# PS1="%n@%m %1~ %# "
# %n 是帐户的用户名。
# %m 是Mac的名称(在 System Preference > Sharing > Computer Name 可修改)。
# %1~ 符号表示当前工作目录(0显示完整的目录),~表示 $ HOME 目录位置。
# %# 表示如果外壳程序以root(管理员)特权运行,则提示符将显示#,否则,则提供%
# PS1="%n@%m %0~ %# "
# Add Git Branch Name to Terminal, set branch highlighting
# https://gist.github.com/reinvanoyen/05bcfe95ca9cb5041a4eafd29309ff29
# https://zsh.sourceforge.io/Doc/Release/Prompt-Expansion.html
function parse_git_branch() {
git branch 2> /dev/null | sed -n -e 's/^\* \(.*\)/(\1)/p'
}
setopt PROMPT_SUBST
export PROMPT='%F{245}%n@%m%f %~ %F{yellow}$(parse_git_branch)%f %# '
Apply change by running:
% source ~/.zshrc
效果如下:
