如何在终端中显示git用户(oh-my-zsh)

时间:2019-09-03 06:27:49

标签: git terminal zsh oh-my-zsh zshrc

我正在与oh-my-zsh交往,并享受spaceship prompt

enter image description here

就像它正在显示我的git分支和状态一样-我如何使其显示在它旁边的当前git用户呢?

(问原因是因为我正在做pair coding,因此这将是有用的信息)

1 个答案:

答案 0 :(得分:1)

您可以通过为宇宙飞船提示编写自定义部分来实现这一目标。

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 ...
)

在初始化提示(飞船)之前,将这两部分放入.zshrc中。

参考

相关问题