Norfeldt
Norfeldt

Reputation: 9718

How to show git user in terminal (oh-my-zsh)

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

enter image description here

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)

Upvotes: 3

Views: 3864

Answers (1)

Simba
Simba

Reputation: 27768

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

Upvotes: 2

Related Questions