需要在修改后的 zshrc 文件中显示之前的文件夹,怎么办?

Need to display previous folder in the modified zshrc file, how do I do it?

这是我当前用于显示 git 分支的 zshrc 文件配置,结果显示带有 git 分支(如果存在)

的当前文件夹
function parse_git_branch() {
    git branch 2> /dev/null | sed -n -e 's/^\* \(.*\)/[]/p'
}

setopt PROMPT_SUBST
export PROMPT='%F{cyan}%.%f %F{blue}$(parse_git_branch)%f%F{normal}$%f '

而不是。在 PROMPT 中,我尝试了 ~ 但它会显示目录的完整路径,但我希望只看到当前目录和上一个目录。我该如何进行?

export PROMPT='%F{cyan}%.%f %F{blue}$(parse_git_branch)%f%F{normal}$%f '

如果我目前在 Documents/gitRepos/project1,终端会显示 project1 [master],我想要的是 gitRepos/project1 [master]

Zsh has this built in:

%c
%.
%C

Trailing component of the current working directory. An integer may folow the '%' to get more than one component. Unless '%C' is used, tilde contraction is performed first. These are deprecated as %c and %C are equivalent to %1~ and %1/., respectively, while explicit positive integers have the same effect as for the latter two sequences.

因此,只需将 %. 替换为 %2.%2~ 或您喜欢的任何内容即可。