The Summer of YS
Today starts a 3 month long, daily summertime journey into the intricacies of YAML and the wisdom of YS! Put on your favorite pair of coding sunglasses, grab a refreshing config drink, and let's get started!
Back in March I promised to start writing more often about all the ways that YS can help you out day-to-day with your YAML interactions. When I last posted here it was barely Spring and now Spring is turning into Summer.
Seasonal turning points be damned, I think of Summer as June, July, and August. In other words...
It's Summer dammit!
Let's declare this Summer, The Summer of YS!
Summertime... and the YAML's Easy🔗
Wanna learn 92 cool things about YAML and YS this Summer? That's one per day, for 3 months!
I've attempted some crazy things in my days (with both success and failure), and this feels pretty crazy, but I'm gonna give it a shot.
I'll post one (mostly short) blog post here each day until the end of August (mostly) about YAML and/or YS.
Today's Handy Tip🔗
I'm not gonna just announce this fiasco and leave you hanging until tomorrow for your first tip. Let's get into it.
I like to keep the lines of most of my text files (including the markdown of this very blog post) at 80 characters or less. You might have a different preference (I still love you) but that's how I roll.
YAML is pretty good at letting you wrap long strings at places of your choosing.
phrase1: The quick brown fox jumped up and down
and all around while the lazy dog just lay
all day with nothing to say.
phrase2:
The quick brown fox jumped up and down and all
around while the lazy dog just lay all day
with nothing to say.
phrase3: "The quick brown fox jumped up and down and all around while the lazy dog just lay all day with nothing to say."
phrase4: "\
The quick brown fox jumped up and down and all around
while the lazy dog just lay all day with nothing to say."
phrase5: >
The quick brown fox jumped up and down and all around
while the lazy dog just lay all day with nothing to say.
These values are all the same. They just use different YAML syntax to wrap the string. YAML generally wraps multiline strings, by collapsing a newline (and leading whitespace) into a single space.
But what if you have a long string with no whitespace at all? This is a common problem when you have long URLs in your YAML files.
There is a way to split these long strings in YAML, and it only works with double quoted scalars.
loong: https://gist.githubusercontent.com/ingydotnet/2e5a79b0b29e548a39a90dba10846042/raw/c05feff49521caf004b5656dcb0e94715a30fffd/stdin
short: "https://gist.githubusercontent.com/\
ingydotnet/\
2e5a79b0b29e548a39a90dba10846042/\
raw/\
c05feff49521caf004b5656dcb0e94715a30fffd/\
stdin"
Just use a backslash at the end of each line in a double quoted scalar and it will collapse without a space.
Are these 2 values exactly the same?
I don't have a magic 8-ball, so let's use (wise ol') YS to find out!
$ ys -pe '_.short == _.loong' - <<'...'
loong: https://gist.githubusercontent.com/ingydotnet/2e5a79b0b29e548a39a90dba10846042/raw/c05feff49521caf004b5656dcb0e94715a30fffd/stdin
short: "https://gist.githubusercontent.com/\
ingydotnet/\
2e5a79b0b29e548a39a90dba10846042/\
raw/\
c05feff49521caf004b5656dcb0e94715a30fffd/\
stdin"
...
true
YS Replies:
It is decidedly so!🔗
See You Tomorrow!🔗
One down, 91 to go!
How hard can this be?
Tomorrow I think I'll show you how to use variables in YAML. You always wanted to know, right?