Move `command_` (back) to `x_`, too verbose

This commit is contained in:
rwxrob 2021-08-31 21:39:57 -04:00
parent e3f8a5cc01
commit 1070f958f7
No known key found for this signature in database
GPG Key ID: 1CCACEDD2F65578E
2 changed files with 25 additions and 21 deletions

View File

@ -15,8 +15,10 @@ This `cmd` inside can then be renamed and finished.
* Name repos containing single bash commands with `cmd-`
* Name template repos beginning with `template-`
* Start command functions with `command_` to be completed
* Start command functions with `command__` to not be completed
* Start command functions with `x_` to be completed
* Start command functions with `x__` to not be completed
Think of the `x` as in "executable" command.
If you want to keep a command but hide it from users just add another
underscore to the prefix which turns it into a hidden command, which
@ -246,5 +248,5 @@ Displays a summary of usage.
----
*Autogenerated Tue Aug 31 09:54:00 AM EDT 2021*
*Autogenerated Tue Aug 31 09:39:48 PM EDT 2021*

38
cmd
View File

@ -35,8 +35,10 @@ This `cmd` inside can then be renamed and finished.
* Name repos containing single bash commands with `cmd-`
* Name template repos beginning with `template-`
* Start command functions with `command_` to be completed
* Start command functions with `command__` to not be completed
* Start command functions with `x_` to be completed
* Start command functions with `x__` to not be completed
Think of the `x` as in "executable" command.
If you want to keep a command but hide it from users just add another
underscore to the prefix which turns it into a hidden command, which
@ -153,7 +155,7 @@ Please mention rwxrob.tv'
HELP[foo]='Foos things.'
command_foo() {
x_foo() {
_filter "$@" && return $?
echo "would foo: $*"
}
@ -166,18 +168,18 @@ HELP[bar]='
Bar the things.'
command_bar() {
x_foo() {
_buffer "$@" && return $?
echo "would bar: $*"
}
HELP[some.config.setting]='Get and set `some.config.setting`.'
command_some.config.setting() {
command_config some.config.setting "$@"
x_some.config.setting() {
x_config some.config.setting "$@"
}
command__hidden() {
x__hidden() {
_filter "$@" && return $?
echo "would run _hidden: $*"
}
@ -190,7 +192,7 @@ command__hidden() {
HELP[usage]='Displays a summary of usage.'
command_usage() {
x_usage() {
local -a cmds
for c in "${COMMANDS[@]}"; do
[[ ${c:0:1} =~ _ ]] && continue
@ -219,7 +221,7 @@ to `$PAGER` (default: more).
Also see `readme` and `usage` commands.
'
command_help() {
x_help() {
local name="${1:-main}" title body
title=$(_help_title "$name") || true
if [[ -z "$title" ]]; then
@ -268,7 +270,7 @@ 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.'
command_readme() {
x_readme() {
_trim "${HELP[main]}"
echo
while IFS= read -r name; do
@ -280,8 +282,8 @@ command_readme() {
echo -e "----\n\n*Autogenerated $(date)*\n"
}
# command_json() { _jsonstr "$@"; }
# command_urlencode() { _urlencode "$@"; }
# x_json() { _jsonstr "$@"; }
# x_urlencode() { _urlencode "$@"; }
# -------------------------- config command --------------------------
@ -352,7 +354,7 @@ Note that this is *not* the same as Java properties and other similar
format. It is designed for ultimate simplicity, efficiency, and
portability.'
command_config() {
x_config() {
case $1 in
dir*) shift; _config_dir "$@"; return $? ;;
path) shift; _config_path "$@"; return $? ;;
@ -503,8 +505,8 @@ _buffer() {
# `complete -C foo foo` > `source <(foo bloated_completion)`
while IFS= read -r line; do
[[ $line =~ ^declare\ -f\ command_ ]] || continue
COMMANDS+=( "${line##declare -f command_}" )
[[ $line =~ ^declare\ -f\ x_ ]] || continue
COMMANDS+=( "${line##declare -f x_}" )
done < <(declare -F)
mapfile -t COMMANDS < \
<(LC_COLLATE=C sort < <(printf "%s\n" "${COMMANDS[@]}"))
@ -522,7 +524,7 @@ _initialize
for c in "${COMMANDS[@]}"; do
if [[ $c == "$EXE" ]]; then
"command_$EXE" "$@"
"x_$EXE" "$@"
exit $?
fi
done
@ -531,10 +533,10 @@ if [[ -n "$1" ]]; then
declare cmd="$1"; shift
for c in "${COMMANDS[@]}"; do
if [[ $c == "$cmd" ]]; then
"command_$cmd" "$@"
"x_$cmd" "$@"
exit $?
fi
done
fi
command_usage "$@"
x_usage "$@"