Add `_jsonstr` helper for JSON one-line strings

This commit is contained in:
rwxrob 2021-08-10 21:32:51 -04:00
parent 55f60d849f
commit 65cd8eb81c
No known key found for this signature in database
GPG Key ID: 1CCACEDD2F65578E
2 changed files with 20 additions and 2 deletions

View File

@ -90,6 +90,12 @@ to `$PAGER` (default: more).
Also see `readme` and `usage` commands.
### The `json` Command
Converts input into JSON string using `jq` containing only escaped
(`
`) line returns.
### Generate `README.md` File
```
@ -106,5 +112,5 @@ Displays a summary of usage.
----
*Autogenerated Tue Aug 10 07:37:40 PM EDT 2021*
*Autogenerated Tue Aug 10 09:32:13 PM EDT 2021*

14
command
View File

@ -96,6 +96,14 @@ command_bar() {
echo "would bar: $*"
}
help[json]='
Converts input into JSON string using `jq` containing only escaped
(`\n`) line returns.'
command_json() {
_jsonstr "$@"
}
command__hidden() {
_filter "$@" && return $?
echo "would run _hidden: $*"
@ -186,7 +194,6 @@ command_readme() {
echo -e "----\n\n*Autogenerated $(date)*\n"
}
_help_title() {
_filter "$@" && return $?;
local name="$1"
@ -202,6 +209,11 @@ _trim() {
echo -e "${it%"${it##*[![:space:]]}"}"
}
_jsonstr() {
_buffer "$@" && return $?
jq -MRsc <<< "$1"
}
_have(){ type "$1" &>/dev/null; }
_filter(){