Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sorting an arbitrary section (with leading spaces) #53

Open
ehawman-rosenberg opened this issue Jun 1, 2022 · 0 comments
Open

Sorting an arbitrary section (with leading spaces) #53

ehawman-rosenberg opened this issue Jun 1, 2022 · 0 comments
Labels
feature New feature or request

Comments

@ehawman-rosenberg
Copy link

YAML to be sorted
# yaml-language-server: $schema=https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json
blocks:
  - type: prompt
    alignment: left
    newline: true
    segments:
      - type: iterm
        style: plain
        foreground: cyan
        template: "{{ .PromptMark }}"
      - type: os
        style: diamond
        trailing_diamond: <transparent,></>
        foreground: cyan
        properties:
          alpine: 
          arch: 
          centos: 
          debian: 
          elementary: 
          fedora: 
          gentoo: 
          linux: 
          macos: 
          manjaro: 
          mint: 
          opensuse: 
          raspbian: 
          ubuntu: 
          windows: 
          wsl: 
          wsl_separator: 
        template: " {{ if .WSL }}{{ end }}{{.Icon}}═"
      - type: shell
        style: diamond
        leading_diamond: 
        background: green
        foreground: black
        template: "  {{ .Name }} "
      - type: session
        style: powerline
        powerline_symbol: 
        background: magenta
        foreground: black
        template: " {{ if .SSHSession }} {{ end }}{{ .UserName }}@{{ .HostName }} "
      - type: angular
        style: powerline
        powerline_symbol: 
        background: lightRed
        foreground: black
        properties:
          fetch_version: true
        template: " ﮰ {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }} "
      - type: aws
        style: powerline
        powerline_symbol: 
        background_templates:
          - '{{if contains "default" .Profile}}yellow{{end}}'
          - '{{if contains "jan" .Profile}}magenta{{end}}'
        foreground: black
        properties:
          display_default: false
        template: "  {{ .Profile }}{{ if .Region }}@{{ .Region }}{{ end }} "
      - type: az
        style: powerline
        powerline_symbol: 
        background: lightBlue
        foreground: black
        properties:
          display_default: false
        template: ' ﴃ Subscription {{ .Name }} ({{ if .EnvironmentName | contains \"AzureCloud\" }}{{ \"Global\" }}{{ else }}{{ .EnvironmentName }}{{ end }}) '
      - type: azfunc
        style: powerline
        powerline_symbol: 
        background: yellow
        foreground: black
        properties:
          display_mode: files
          fetch_version: false
        template: " ﴃ {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }} "
      - type: cds
        style: powerline
        powerline_symbol: 
        template: '  cds {{ .Full }} '
      - type: go
        style: powerline
        powerline_symbol: 
        background: lightCyan
        foreground: black
        properties:
          fetch_version: true
        template: "  {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }} "
      - type: java
        style: powerline
        powerline_symbol: 
        background: lightCyan
        foreground: black
        template: "  {{ .Full }}"
      - type: julia
        style: powerline
        powerline_symbol: 
        background: lightCyan
        foreground: black
        properties:
          fetch_version: true
        template: "  {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }} "
      - type: kubectl
        style: powerline
        powerline_symbol: 
        background: lightYellow
        foreground: black
        template: " ﴱ {{.Context}}{{if .Namespace}} :: {{.Namespace}}{{end}} "
      - type: node
        style: powerline
        powerline_symbol: 
        background: lightGreen
        foreground: black
        properties:
          fetch_version: true
        template: "  {{ if .PackageManagerIcon }}{{ .PackageManagerIcon }} {{ end }}{{ .Full }} "
      - type: php
        style: powerline
        powerline_symbol: 
        background: lightCyan
        foreground: black
        template: "  {{ .Full }} "
      - type: project
        style: powerline
        powerline_symbol: 
        background: lightYellow
        foreground: black
        template: " {{ if .Error }}{{ .Error }}{{ else }}{{ if .Version }} {{.Version}}{{ end }} {{ if .Name }}{{ .Name }}{{ end }}{{ end }} "
      - type: python
        style: powerline
        powerline_symbol: 
        background: lightYellow
        foreground: black
        properties:
          display_mode: files
          fetch_virtual_env: false
        template: "  {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }} "
      - type: ruby
        style: powerline
        powerline_symbol: 
        background: red
        foreground: black
        properties:
          display_mode: files
          fetch_version: true
        template: "  {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }} "
      - type: time
        style: powerline
        powerline_symbol: 
        background: yellow
        foreground: black
        properties:
          time_format: Mon | 15:04:05
        template: " {{ .CurrentDate | date .Format }} "
      - type: executiontime
        style: diamond
        trailing_diamond: 
        background: cyan
        foreground: black
        properties:
          style: austin
          threshold: 0
        template: " {{ .FormattedMs }} "
  - type: prompt
    alignment: right
    segments:
      - type: git
        style: diamond
        leading_diamond: 
        trailing_diamond: 
        background: magenta
        foreground: black
        properties:
          branch_icon: ""
          fetch_stash_count: true
          fetch_status: true
          fetch_upstream_icon: true
          fetch_worktree_count: true
        template: "{{ .UpstreamIcon }}{{ .HEAD }}{{ .BranchStatus }}{{ if .Working.Changed }}  {{ .Working.String }}{{ end }}{{ if and (.Working.Changed) (.Staging.Changed) }} |{{ end }}{{ if .Staging.Changed }}  {{ .Staging.String }}{{ end }}{{ if gt .StashCount 0 }}  {{ .StashCount }}{{ end }}"
  - type: prompt
    alignment: left
    newline: true
    segments:
      - type: text
        style: plain
        foreground: cyan
        template: ""
      - type: exit
        style: diamond
        leading_diamond: 
        background: blue
        background_templates:
          - "{{ if gt .Code 0 }}red{{ end }}"
        foreground: black
        properties:
          always_enabled: true
        template: "{{ if gt .Code 0 }}  {{ else }} {{ end }}"
      - type: path
        style: powerline
        powerline_symbol: 
        background: blue
        background_templates:
          - "{{ if not .Writable }}red{{ end }}"
        foreground: black
        properties:
          style: agnoster_short
          folder_icon: 
          folder_separator_icon: ""
          home_icon: 
          max_depth: 3
        template: "{{ if gt .Code 0 }} {{ else }}{{ end }} {{ .Path }}{{ if not .Writable }}  {{  end  }}"
      - type: text
        style: accordion
        powerline_symbol: 
        background: blue
        background_templates:
          - "{{ if and .Segments.Path.Writable (not .Root) }}{{ else }}red{{ end }}"
        foreground: white
        properties:
          root_icon: 
        template: "{{ if and .Root (not .Segments.Path.Writable) }}  {{ end }}{{ if and .Root .Segments.Path.Writable }}  {{ end }}"
console_title_template: "{{ .Folder }}"
osc99: true
palette:
  black: "#1B1A23"
  blue: "#9580FF"
  black-background: "#22212C"
  lightBlue-brightBlue: "#AA99FF"
  lightCyan-brightCyan: "#99FFEE"
  lightGreen-brightGreen: "#A2FF99"
  lightMagenta-brightPurple: "#FF99CC"
  lightRed-brightRed: "#FFAA99"
  lightWhite-brightWhite: "#FFFFFF"
  lightYellow-brightYellow: "#FFFF80"
  selection-selectionBackground: "#454158"
  comment-brightBlack: "#7970A9"
  cyan: "#80FFEA"
  green: "#8AFF80"
  magenta-purple: "#FF80BF"
  red: "#FF9580"
  white-cursorColor-foreground: "#F8F8F2"
  yellow: "#FFCA80"
version: 2

Let's say I wanted to sort from Line 46 - type: angular to Line 150 template: "  {{ if .Error }}{{ .Error }}{{ else }}{{ .Full }}{{ end }} ". This is a subset of a list. I select my text, summon vscode-yaml-sort, and...

YAML selection is invalid. Please check the ending of your selection.
YAML is invalid: bad indentation of a mapping entry (2:14)

 1 | - type: angular
 2 |         style: powerline
------------------^
 3 |         powerline_symbol: 
 4 |         background: lightRed

I have to shift-tab them back over to the left so they're valid YAML before running vscode-yaml-sort, then tab them back home again. It would be nice if the extension could identify left-aligned blocks of whitespace shared by all lines in a text selection, then ignore them before it validates the YAML.

Ultimately I'd like to be able to sort the list elements by a specific key shared by all (Type, or the first key in this case), but I recognize that is a whole other layer of complexity.

@pascalre pascalre added the feature New feature or request label Aug 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants