From 5d008a73e9346e420db58a7d7d75f18563bb0790 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Sun, 21 Feb 2021 18:36:31 -0600 Subject: [PATCH] Add Create Multi-Line Strings Without The Line Breaks as a yaml til --- README.md | 7 +++++- ...ti-line-strings-without-the-line-breaks.md | 22 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 yaml/create-multi-line-strings-without-the-line-breaks.md diff --git a/README.md b/README.md index 2018516..066e47e 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud). -_1057 TILs and counting..._ +_1058 TILs and counting..._ --- @@ -58,6 +58,7 @@ _1057 TILs and counting..._ * [VSCode](#vscode) * [Webpack](#webpack) * [Workflow](#workflow) +* [YAML](#yaml) --- @@ -1242,6 +1243,10 @@ _1057 TILs and counting..._ - [Update asdf Plugins With Latest Package Versions](workflow/update-asdf-plugins-with-latest-package-versions.md) - [View The PR For The Current GitHub Branch](workflow/view-the-pr-for-the-current-github-branch.md) +## YAML + +- [Create Multi-Line Strings Without The Line Breaks](yaml/create-multi-line-strings-without-the-line-breaks.md) + ## Usage The `.vimrc` file for this project contains a function `CountTILs` that can diff --git a/yaml/create-multi-line-strings-without-the-line-breaks.md b/yaml/create-multi-line-strings-without-the-line-breaks.md new file mode 100644 index 0000000..a220b31 --- /dev/null +++ b/yaml/create-multi-line-strings-without-the-line-breaks.md @@ -0,0 +1,22 @@ +# Create Multi-Line Strings Without The Line Breaks + +There are [many ways](https://stackoverflow.com/a/21699210/535590) to add +multi-line strings to a YAML document. Most of them preserve the literal +newlines present in the multi-line string. And generally that is what you want +in a multi-line string. + +Sometimes, however, you want a multi-line string just for its readability in +the file. The literal representation of the string should exclude the newlines. +To achieve this, you can use either `>-` or `|-`. + +```yaml +run: >- + echo "::set-output name=NODE_VERSION::$( + cat .tool-versions + | grep nodejs + | sed 's/nodejs \(.*\)$/\1/' + )" +``` + +This creates a readable key-value pair without introducing newline characters +into the string that represents a shell command.