From 9538f613a6be131a5cdb33ed736fc32d28445de8 Mon Sep 17 00:00:00 2001 From: Jan Klass Date: Thu, 30 May 2024 13:45:59 +0200 Subject: [PATCH] Change inline code to code blocks (#1426) for syntax highlighting as discussed in PR #1425 --- book/cheat_sheet.md | 78 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 65 insertions(+), 13 deletions(-) diff --git a/book/cheat_sheet.md b/book/cheat_sheet.md index 61e50ad7cc..f8e3c8fa46 100644 --- a/book/cheat_sheet.md +++ b/book/cheat_sheet.md @@ -2,15 +2,35 @@ ## Data types -convert string to integer: `"12" | into int` +convert string to integer: -convert present date to provided time zone: `date now | date to-timezone "Europe/London"` +```nu +"12" | into int +``` + +convert present date to provided time zone: + +```nu +date now | date to-timezone "Europe/London" +``` + +update a record's language and if none is specified insert provided value: + +```nu +{'name': 'nu', 'stars': 5, 'language': 'Python'} | upsert language 'Rust' +``` -update a record's language and if none is specified insert provided value: `{'name': 'nu', 'stars': 5, 'language': 'Python'} | upsert language 'Rust'` +convert list of strings to yaml: -convert list of strings to yaml: `[one two three] | to yaml` +```nu +[one two three] | to yaml +``` + +print table data: -print table data: `[[framework, language]; [Django, Python] [Laravel, PHP]]` +```nu +[[framework, language]; [Django, Python] [Laravel, PHP]] +``` select two named columns from the table and print their values: @@ -233,9 +253,17 @@ slice items that satisfy provided condition: ## Tables -sort table: `ls | sort-by size` +sort table: -sort table, get first rows: `ls | sort-by size | first 5` +```nu +ls | sort-by size +``` + +sort table, get first rows: + +```nu +ls | sort-by size | first 5 +``` concatenate two tables with same columns: @@ -268,17 +296,41 @@ remove the last column of a table: ## Files & Filesystem -open a text file with the default text editor: `start file.txt` +open a text file with the default text editor: + +```nu +start file.txt +``` + +save a string to text file: -save a string to text file: `'lorem ipsum ' | save file.txt` +```nu +'lorem ipsum ' | save file.txt +``` -append a string to the end of a text file: `'dolor sit amet' | save --append file.txt` +append a string to the end of a text file: -save a record to file.json: `{ a: 1, b: 2 } | save file.json` +```nu +'dolor sit amet' | save --append file.txt +``` -recursively search for files by file name: `glob **/*.{rs,toml} --depth 2` +save a record to file.json: -watch a file, run command whenever it changes: `watch . --glob=**/*.rs {|| cargo test }` +```nu +{ a: 1, b: 2 } | save file.json +``` + +recursively search for files by file name: + +```nu +glob **/*.{rs,toml} --depth 2 +``` + +watch a file, run command whenever it changes: + +```nu +watch . --glob=**/*.rs {|| cargo test } +``` ## Custom Commands