我正在使用 oh-my-zsh 并享受 spaceship prompt,非常愉快。
就像它显示我的git分支和状态一样 - 我如何使它在旁边显示我的当前git用户?
(询问的原因是因为我正在进行配对编码,因此这将是有用的信息)
spaceship_git_user() {
spaceship::is_git || return
local username
username="$(git config user.name)"
if [[ -n $username ]]; then
spaceship::section \
"magenta" \
"$username"
fi
}
SPACESHIP_PROMPT_ORDER=(
# content omitted ...
git_user
# content omitted ...
)
在你的提示符(spaceship)初始化之前,将这两个部分放入你的 .zshrc
中。
参考资料
git
而不是其他任何东西,这个功能在一个简单的仓库中没有任何花哨的东西是默认的。 - Michaelgit log
命令中获取用户信息,虽然有许多选项与提交相关,但没有与用户相关的内容(你可以获取提交者的详细信息)。https://git-scm.com/docs/git-log - Michaelgit config user.name
并以某种方式在终端中显示它 - 就像它显示未暂存的文件等一样。 - Norfeldt