Skip to content

Ability to use templating on segment options #7243

@allRisc

Description

@allRisc

Code of Conduct

  • I agree to follow this project's Code of Conduct

What would you like to see added?

I am currently working on a prompt that ensures the working directory doesn't wrap, but which provides as much information about the working dir as possible.

As it stands today in order to accomplish this i leverage min_width and max_width to selectively hide a bunch of segments in order to semi-dynamically set the powerlevel's max_width option. This leads to ugly and hard to maintain code:

  [[blocks]]
    type = 'prompt'
    alignment = 'left'

    [[blocks.segments]]
      template = '{{ .Path }} '
      type = 'path'

      max_width=69

      [blocks.segments.options]
        max_width=30
        style = 'powerlevel'

    [[blocks.segments]]
      template = '{{ .Path }} '
      type = 'path'

      min_width=70
      max_width=99

      [blocks.segments.options]
        max_width=40
        style = 'powerlevel'

    [[blocks.segments]]
      template = '{{ .Path }} '
      type = 'path'

      min_width=100
      max_width=129

      [blocks.segments.options]
        max_width=70
        style = 'powerlevel'

    [[blocks.segments]]
      template = '{{ .Path }} '
      type = 'path'

      min_width=130

      [blocks.segments.options]
        max_width=100
        style = 'powerlevel'

Instead something akin to the following where we could dynamically set it using environment variables would be ideal.

  [[blocks]]
    type = 'prompt'
    alignment = 'left'

    [[blocks.segments]]
      template = '{{ .Path }} '
      type = 'path'
      style = 'plain'

      [blocks.segments.options]
        max_width = "{{ atoi(.Env.COLUMNS) - 30 }}"
        style = 'powerlevel'

Metadata

Metadata

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions