Skip to content

Instantly share code, notes, and snippets.

@briantjacobs
Created November 24, 2015 19:43
Show Gist options
  • Save briantjacobs/7753bf850ca5e39be409 to your computer and use it in GitHub Desktop.
Save briantjacobs/7753bf850ca5e39be409 to your computer and use it in GitHub Desktop.

Revisions

  1. Mark Milstein revised this gist Oct 2, 2015. 3 changed files with 43 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions config.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    development:
    adapter: mysql2
    encoding: utf8
    database: my_database
    username: root
    password:
    apt:
    - somepackage
    - anotherpackage
    6 changes: 6 additions & 0 deletions result
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    development_adapter=("mysql2")
    development_encoding=("utf8")
    development_database=("my_database")
    development_username=("root")
    development_apt+=("somepackage")
    development_apt+=("anotherpackage")
    28 changes: 28 additions & 0 deletions yaml.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    #!/usr/bin/env bash
    #
    # vim: set ft=sh:
    #
    # Based on https://gist.github.com/pkuczynski/8665367

    parse_yaml() {
    local prefix=$2
    local s
    local w
    local fs
    s='[[:space:]]*'
    w='[a-zA-Z0-9_]*'
    fs="$(echo @|tr @ '\034')"
    sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
    -e "s|^\($s\)\($w\)$s[:-]$s\(.*\)$s\$|\1$fs\2$fs\3|p" "$1" |
    awk -F"$fs" '{
    indent = length($1)/2;
    vname[indent] = $2;
    for (i in vname) {if (i > indent) {delete vname[i]}}
    if (length($3) > 0) {
    vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
    printf("%s%s%s=(\"%s\")\n", "'"$prefix"'",vn, $2, $3);
    }
    }' | sed 's/_=/+=/g'
    }

    parse_yaml config.yml
  2. Mark Milstein revised this gist Oct 2, 2015. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1 +0,0 @@
    bla
  3. Mark Milstein created this gist Oct 2, 2015.
    1 change: 1 addition & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    bla