Yaml

From wikinotes
Revision as of 02:38, 2 May 2020 by Will (talk | contribs) (→‎Anchors/Aliases)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

YAML is a very convenient information storage language. Because of how space-sensitive it is, (both before and after line), I don't recommend it for user-modifiable configurations, it is very touchy.

For personal configs, however, it is quite suitable.

Example

kodi:
   pkg_name:
      archlinux: [ kodi ]

   pkg_conf:
      archlinux:
         standard: 
            -
               cfg: $config/xbmc/romCollectionBrowser__config.xml
               dst: $HOME/.xbmc/userdata/addon_data/script.games.rom.collection.browser/config.xml
            -
               cfg: $config/xbmc/keyboard.xml
               dst: $HOME/.kodi/userdata/keymaps/keyboard.xml

Anchors/Aliases

  • You can store/reuse reusable chunks of configuration within yaml
some_key: &variable_name
  a: 1
  b: 
    - 1
    - 2

some_other_key: *variable_name
yet_another_key: *varaible_name

datatypes

String

See YAML documentation for block chomping indicator: https://yaml.org/spec/1.2/spec.html#id2794534

var: foo
var: "foo"

var: |
  keeps
  line breaks

var: >
  ignores
  line breaks,
  adds \n following string

var: >-
  ignores
  line breaks,
  no \n following string

# also supported
#
#  |   >
#  |+  >+
#  |-  >-

NoneType

var: Null

dict

a: 1
b: 2
##> {'a':1, 'b':2}
my_dict:
  a: 1
  b: 2
##> {'my_dict' : {'a':1, 'b':2}

list

## Both pythonic and YAML-like
## syntax is alright.
[ a, b, c, d ]

-
 a
 b
 c
 d

##> [ 'a','b','c','d' ]

list of dicts

-
  aaa: 1
  bbb: 2
-
  aaa: 1
  bbb: 2

##> [{aaa:1,bbb:2},{aaa:1,bbb:2}]