如何在终端中显示 git 用户 (oh-my-zsh) [英] How to show git user in terminal (oh-my-zsh)

查看:48
本文介绍了如何在终端中显示 git 用户 (oh-my-zsh)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 oh-my-zsh 玩得很开心,并享受了

就像它显示我的 git 分支和状态一样 - 我怎样才能让它在旁边显示我当前的 git 用户?

(问的原因是因为我正在做配对编码,因此它会有用的信息)

解决方案

您可以通过为 spaceship-prompt 编写自定义部分来实现此目的.

spaceship_git_user() {宇宙飞船::is_git ||返回本地用户名用户名="$(git config user.name)"如果 [[ -n $username ]];然后宇宙飞船::部分\洋红色"\$用户名"菲}

然后,将自定义部分添加到飞船提示中.

SPACESHIP_PROMPT_ORDER=(# 内容省略...git_user# 内容省略...)

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

参考资料

I'm having a blast with oh-my-zsh and enjoying the spaceship prompt.

Just like it is showing my git branch and status - how can I make it show my current git user right next to that?

(The reason for asking is because I'm doing pair coding and it would therefore be useful info)

解决方案

You can achieve this by writing a custom section for spaceship-prompt.

spaceship_git_user() {
  spaceship::is_git || return

  local username

  username="$(git config user.name)"

  if [[ -n $username ]]; then
    spaceship::section \
      "magenta" \
      "$username"
  fi
}

Then, add the custom section into spaceship prompt.

SPACESHIP_PROMPT_ORDER=(
  # content omitted ...

  git_user

  # content omitted ...
)

Put these two parts into your .zshrc before your prompt (spaceship) is initialized.

References

这篇关于如何在终端中显示 git 用户 (oh-my-zsh)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆