powerlevel10k: Inconsistent space between segments depending on the background color of a custom p10k segment

Hello. I am trying to add a custom segment called drd_dev_env. I have it at the end of my POWERLEVEL9K_LEFT_PROMPT_ELEMENTS like this:

    # =========================[ Line #2 ]=========================
    drd_dev_env             # Development environment: prod/staging/test
    context                 # user@hostname
    prompt_char             # prompt symbol
)

If I define an empty background color, there is a space between this segment and context:

  typeset -g POWERLEVEL9K_DRD_DEV_ENV_BACKGROUND=
  function prompt_drd_dev_env() {
    if [[ ! -z $DRD_DEV_ENV ]]; then
      p10k segment -f white -t "$DRD_DEV_ENV"
    fi
  }
p10k-empy-bg

However, if I define a non-empty background color, there is not a space between this segment and context:

  typeset -g POWERLEVEL9K_DRD_DEV_ENV_BACKGROUND='black'
  function prompt_drd_dev_env() {
    if [[ ! -z $DRD_DEV_ENV ]]; then
      p10k segment -f white -t "$DRD_DEV_ENV"
    fi
  }
p10k-black-bg

Is there any way to explicitly control this behavior?

I am using the P10k from git at commit 16e5848.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (8 by maintainers)

Most upvoted comments

I like to have the prompt text only be three characters

typeset -gA drd_dev_env=(
  PROD    '%F{002}PRD'
  STAGING '%F{033}STG'
  TEST    '%F{129}TST'
)

function prompt_drd_dev_env() {
  p10k segment -t "${drd_dev_env[$DRD_DEV_ENV]}"
}

Looks good. I’d implement it like this:

typeset -gA drd_dev_env_colors=(
  PROD    green
  STAGING 33
  TEST    purple
)

function prompt_drd_dev_env() {
  local color=${drd_dev_env_colors[$DRD_DEV_ENV]}
  [[ -n $color ]] || return
  p10k segment -f $color -t "%B$DRD_DEV_ENV"
}

You don’t have to use POWERLEVEL9K_* overrides when working with your own prompt segment. No need to override what you’ve custom made for yourself.

My suggestion is to use foreground colors and/or icons to call attention to a segment.

I probably want POWERLEVEL9K_LEFT_SEGMENT_SEPARATOR set to a space, too.

Sure, you can do that, although as I mentioned above, I don’t think it’s a good idea to use background colors with Lean style.

Left prompt segments with the same background color are separated by POWERLEVEL9K_LEFT_SUBSEGMENT_SEPARATOR. Left prompt segments with different background colors are separated by POWERLEVEL9K_LEFT_SEGMENT_SEPARATOR. I suppose in your config the former is set to ' ' and the latter to ''. You can verify with the following command:

typeset -p POWERLEVEL9K_LEFT_SUBSEGMENT_SEPARATOR POWERLEVEL9K_LEFT_SEGMENT_SEPARATOR

I also suppose that your config is based on Lean style. It’s a good choice. I also use Lean. In this style you don’t use background colors and convey information by content, icons and foreground colors only.