2021-08-10 17:47:07 -05:00
|
|
|
# Bash Template Command
|
|
|
|
|
2021-08-10 18:15:33 -05:00
|
|
|
*This `README.md` is autogenerated.*
|
2021-08-06 12:48:11 -05:00
|
|
|
|
2021-08-09 09:22:17 -05:00
|
|
|
This is a GitHub template repo that will be copied instead of forked to
|
|
|
|
create a new Bash command with a command something like this:
|
2021-08-08 20:34:35 -05:00
|
|
|
|
|
|
|
```
|
2021-08-09 09:22:17 -05:00
|
|
|
gh repo create rwxrob/mycmd -p rwxrob/template-bash-command
|
2021-08-08 20:34:35 -05:00
|
|
|
```
|
|
|
|
|
2021-08-23 21:10:27 -05:00
|
|
|
This `cmd` inside can then be renamed and finished.
|
2021-08-10 17:47:07 -05:00
|
|
|
|
2021-08-09 09:22:17 -05:00
|
|
|
Obviously, not all of this is needed for many Bash scripts, but anything
|
|
|
|
with more than two subcommands will benefit from the builtin tab
|
|
|
|
completion, embedded Markdown help documentation support, and included
|
2021-08-09 18:01:36 -05:00
|
|
|
functions (`usage`, `_filter`, `_buffer`, `_have`, etc.)
|
2021-08-06 12:48:11 -05:00
|
|
|
|
2021-08-08 20:24:27 -05:00
|
|
|
## Naming Conventions
|
|
|
|
|
2021-08-09 09:22:17 -05:00
|
|
|
* Name repos containing single bash commands with `cmd-`
|
|
|
|
* Name template repos beginning with `template-`
|
2021-08-10 11:52:00 -05:00
|
|
|
* Start command functions with `command_` to be completed
|
|
|
|
* Start command functions with `command__` to not be completed
|
2021-08-08 20:24:27 -05:00
|
|
|
|
2021-08-06 12:48:11 -05:00
|
|
|
## Dependencies
|
|
|
|
|
|
|
|
Required:
|
|
|
|
|
|
|
|
* Bash 4+
|
|
|
|
|
|
|
|
Optional:
|
|
|
|
|
|
|
|
* `pandoc` - for rich help docs
|
2021-08-23 21:10:27 -05:00
|
|
|
* `jq` - for `json` and anything that uses it
|
2021-08-06 12:48:11 -05:00
|
|
|
|
|
|
|
## Justification
|
|
|
|
|
|
|
|
Bash is the dominate shell scripting language and the official default
|
|
|
|
Linux interactive shell, which reduces cognitive overhead; every command
|
|
|
|
line *is* a line of code that could be put into script as is. Bash
|
|
|
|
scripts are at the core of cloud, containers, and Kubernetes. Bash 4+
|
|
|
|
with its associative array support, powerful regular expressions, and
|
|
|
|
multiple ways of feeding data to loops easily covers the needs
|
|
|
|
previously requiring Python and Perl scripts. Bash scripts are also much
|
|
|
|
more powerful, safer, flexible, and performant than POSIX shell or Zsh.
|
|
|
|
|
2021-08-10 18:37:51 -05:00
|
|
|
## Guidelines
|
2021-08-06 12:48:11 -05:00
|
|
|
|
2021-08-10 18:37:51 -05:00
|
|
|
* Write GitHub Flavored Markdown only
|
|
|
|
* Use present tense ("outputs" over "will output")
|
2021-08-23 21:10:27 -05:00
|
|
|
* Prefer term "output" and "display" over ~~print~~
|
2021-08-10 18:37:51 -05:00
|
|
|
* Follow the [naming conventions](#naming-conventions)
|
2021-08-15 15:56:56 -05:00
|
|
|
* Use the official bash path: `#!/bin/bash`
|
|
|
|
* Use of `#!/usr/bin/bash` is outdated
|
2021-08-06 12:48:11 -05:00
|
|
|
* Using `#!/usr/bin/env bash` introduces unnecessary risk
|
2021-08-10 18:37:51 -05:00
|
|
|
* Explicitly export `PATH` in script when possible
|
2021-08-06 12:48:11 -05:00
|
|
|
* Always check script with [`shellcheck`] before releasing
|
|
|
|
* Always use `bc` for *any* floating point math
|
|
|
|
|
|
|
|
[`shellcheck`]: <https://www.shellcheck.net>
|
|
|
|
|
|
|
|
## Legal
|
|
|
|
|
2021-08-06 12:50:56 -05:00
|
|
|
Copyright 2021 Rob Muhlestein <rob@rwx.gg>
|
|
|
|
Released under Apache-2.0 License
|
2021-08-15 15:56:56 -05:00
|
|
|
Please mention <https://rwxrob.tv>
|
2021-08-10 17:47:07 -05:00
|
|
|
|
2021-08-23 21:10:27 -05:00
|
|
|
## The `bar` Command
|
2021-08-10 17:47:07 -05:00
|
|
|
|
2021-08-23 21:10:27 -05:00
|
|
|
```
|
|
|
|
cmd bar
|
|
|
|
```
|
|
|
|
|
|
|
|
Bar the things.
|
|
|
|
|
|
|
|
## The `config` Command
|
|
|
|
|
|
|
|
```
|
|
|
|
cmd config
|
|
|
|
cmd config KEY
|
|
|
|
cmd config KEY VALUE
|
|
|
|
```
|
|
|
|
|
|
|
|
The `config` command is for reading, writing, and displaying standard
|
2021-08-23 21:21:28 -05:00
|
|
|
open desktop configuration properties.
|
2021-08-23 21:10:27 -05:00
|
|
|
|
|
|
|
### Arguments
|
2021-08-10 17:47:07 -05:00
|
|
|
|
2021-08-23 21:10:27 -05:00
|
|
|
With no arguments outputs all the currently cached configuration
|
|
|
|
settings.
|
2021-08-10 17:47:07 -05:00
|
|
|
|
2021-08-23 21:10:27 -05:00
|
|
|
With a single KEY argument fetches the value for that key and outputs
|
|
|
|
it.
|
2021-08-10 17:47:07 -05:00
|
|
|
|
2021-08-23 21:10:27 -05:00
|
|
|
With more than one argument the remaining arguments after the KEY will
|
2021-08-23 21:21:28 -05:00
|
|
|
be combined into the VALUE and written to a `values` file in the
|
2021-08-23 21:10:27 -05:00
|
|
|
standard configuration home location (Search for `XDG_CONFIG_HOME` for
|
|
|
|
more information).
|
2021-08-10 17:47:07 -05:00
|
|
|
|
2021-08-23 21:23:32 -05:00
|
|
|
### Configuration `values` File Format
|
2021-08-23 21:10:27 -05:00
|
|
|
|
2021-08-23 21:21:28 -05:00
|
|
|
The file (which is almost always located at
|
|
|
|
`~/.config/cmd/values`) uses the simplest possible format to
|
2021-08-23 21:14:42 -05:00
|
|
|
facilitate standard UNIX parsing and filtering with any number of
|
|
|
|
existing tools (and no `jq` dependency).
|
2021-08-23 21:10:27 -05:00
|
|
|
|
|
|
|
* One KEY=VALUE per line
|
|
|
|
* KEYs may be anything but the equal sign (`=`)
|
|
|
|
* VALUEs may be anything but line returns must be escaped
|
|
|
|
|
|
|
|
Note that this is *not* the same as Java properties and other similar
|
|
|
|
format. It is designed for ultimate simplicity, efficiency, and
|
|
|
|
portability.
|
|
|
|
|
|
|
|
## The `foo` Command
|
|
|
|
|
|
|
|
Foos things.
|
|
|
|
|
|
|
|
## The `help` Command
|
2021-08-10 17:47:07 -05:00
|
|
|
|
|
|
|
```
|
2021-08-23 21:10:27 -05:00
|
|
|
cmd help [COMMAND]
|
2021-08-10 17:47:07 -05:00
|
|
|
```
|
|
|
|
|
|
|
|
Displays specific help information. If no argument is passed displays
|
|
|
|
general help information (main). Otherwise, the documentation for the
|
|
|
|
specific argument keyword is displayed, which usually corresponds to
|
2021-08-23 21:10:27 -05:00
|
|
|
a COMMAND name (but not necessarily). All documentation is written in
|
2021-08-10 17:47:07 -05:00
|
|
|
GitHub Flavored Markdown and will displayed as a web page if `pandoc`
|
|
|
|
and `$HELP_BROWSER` are detected, otherwise, just the Markdown is sent
|
|
|
|
to `$PAGER` (default: more).
|
|
|
|
|
|
|
|
Also see `readme` and `usage` commands.
|
|
|
|
|
2021-08-23 21:10:27 -05:00
|
|
|
## Convert to JSON String
|
|
|
|
|
|
|
|
```
|
|
|
|
cmd json STRING
|
|
|
|
cmd json <<< STRING
|
|
|
|
cmd json < FILE
|
|
|
|
cmd json < <(COMMAND)
|
|
|
|
```
|
2021-08-10 20:32:51 -05:00
|
|
|
|
2021-08-23 21:10:27 -05:00
|
|
|
Converts input into JSON string using `jq` (if found) containing only
|
|
|
|
escaped (`\n`) line returns.
|
2021-08-10 20:32:51 -05:00
|
|
|
|
2021-08-23 21:10:27 -05:00
|
|
|
## Generate `README.md` File
|
2021-08-10 17:47:07 -05:00
|
|
|
|
|
|
|
```
|
2021-08-23 21:10:27 -05:00
|
|
|
cmd readme > README.md
|
2021-08-10 17:47:07 -05:00
|
|
|
```
|
|
|
|
|
|
|
|
The `readme` command will output the embedded help documentation in raw
|
|
|
|
GitHub Flavored Markdown suitable for use as a `README.md` file on
|
|
|
|
GitHub or similar hosting service.
|
|
|
|
|
2021-08-23 21:10:27 -05:00
|
|
|
## The `usage` Command
|
2021-08-10 17:47:07 -05:00
|
|
|
|
|
|
|
Displays a summary of usage.
|
2021-08-06 12:48:11 -05:00
|
|
|
|
2021-08-10 18:15:33 -05:00
|
|
|
----
|
|
|
|
|
2021-08-23 21:23:32 -05:00
|
|
|
*Autogenerated Mon Aug 23 10:23:26 PM EDT 2021*
|
2021-08-10 18:15:33 -05:00
|
|
|
|