Spaceship-prompt: [Feature Request] Show git user name in the "right prompt"

Created on 10 Sep 2019  路  4Comments  路  Source: denysdovhan/spaceship-prompt

First off. I'm VERY 馃槂馃槃馃榾 with this spaceship-prompt! It's delicious 馃構

Is your feature request related to a problem? Please describe.

The problem is that I'm doing pair coding and therefore changing the git username frequently.

*Is your feature request related to new section on prompt? *

I wish to use the existing right side prompt to show the user - just like some use it to display date and time.

Describe the solution you'd like

Would just like to learn how to make an rprompt that shows the git user name.

.../repo/app via node v.12.4.0 via ruby ruby-2.6.3
on branch bug/just-make-it-work
$ add .                                                             [Alice & Bob]

Imagine that it calls git config --global user.name on every prompt "refresh/load" and puts in to the right

Describe alternatives you've considered

Either have it as an option (like shown below)

or

Instruct me how to make a custom option that gets call every time the prompt loads.

Documentation, adoption

SPACESHIP_RPROMPT_ORDER=(
  #time      # Time stamps section
  gituser    # Git user name
)
proposal

Most helpful comment

I found a solution! https://stackoverflow.com/a/57900968/618099

TLDR:

spaceship_git_user() {
  spaceship::is_git || return

  local username

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

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

Then, add the custom section into spaceship prompt.

SPACESHIP_RPROMPT_ORDER =(
  # content omitted ...

  git_user

  # content omitted ...
)

All 4 comments

I found a solution! https://stackoverflow.com/a/57900968/618099

TLDR:

spaceship_git_user() {
  spaceship::is_git || return

  local username

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

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

Then, add the custom section into spaceship prompt.

SPACESHIP_RPROMPT_ORDER =(
  # content omitted ...

  git_user

  # content omitted ...
)

One minor suggestion, It's better to quote uninitiated variables or initialize it there. See #420

@salmanulfarzy Sorry, I do not understand what you mean?

If you happen to have local variable named username, it would break prompt rendering by displaying variable value instead of that from script, quoting variable declaration prevents it. Use one of the following,

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

or

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

This is discussed at #420

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xhaythemx picture xhaythemx  路  3Comments

AlecRust picture AlecRust  路  3Comments

salmanulfarzy picture salmanulfarzy  路  3Comments

conradwt picture conradwt  路  3Comments

olets picture olets  路  3Comments