代码之家  ›  专栏  ›  技术社区  ›  Norfeldt

如何在终端中显示git用户(哦,我的zsh)

  •  0
  • Norfeldt  · 技术社区  · 7 年前

    spaceship prompt .

    enter image description here

    就像它显示我的git分支和状态一样-如何让它显示我当前的git用户?

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

    0 回复  |  直到 7 年前
        1
  •  2
  •   Simba Thomas Chaton    7 年前

    您可以通过为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
    }
    

    SPACESHIP_PROMPT_ORDER=(
      # content omitted ...
    
      git_user
    
      # content omitted ...
    )
    

    把这两部分放到你的 .zshrc 在提示符(宇宙飞船)初始化之前。