From 1070f958f7cbea2317b64651ca7ad0f164444c87 Mon Sep 17 00:00:00 2001 From: rwxrob Date: Tue, 31 Aug 2021 21:39:57 -0400 Subject: [PATCH] Move `command_` (back) to `x_`, too verbose --- README.md | 8 +++++--- cmd | 38 ++++++++++++++++++++------------------ 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index e7fcadd..6c8c14c 100644 --- a/README.md +++ b/README.md @@ -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* diff --git a/cmd b/cmd index 9f46712..91d9fc7 100755 --- a/cmd +++ b/cmd @@ -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 "$@"