Move from `x_` to `x.` with explanation

This commit is contained in:
rwxrob 2021-08-31 22:38:13 -04:00
parent 159b2e78d7
commit eedc4a7021
No known key found for this signature in database
GPG Key ID: 1CCACEDD2F65578E
2 changed files with 38 additions and 18 deletions

View File

@ -15,10 +15,20 @@ This `cmd` inside can then be renamed and finished.
* Name repos containing single bash commands with `cmd-` * Name repos containing single bash commands with `cmd-`
* Name template repos beginning with `template-` * Name template repos beginning with `template-`
* Start command functions with `x_` to be completed * Start command functions with `x.` to be completed
* Name `CONFIG` accessors with `x.` and full path
* Use dot (`.`) pathing in `CONFIG` key names
Think of `x` as in "executable" command. Think of `x` as in "executable" command.
> ⚠️
> Note that all versions of Vim current have a bug that does not allow
> dot (`.`) to be included in the function name even though it is
> explicitly allowed by bash. So you may have to add `.` to your
> `/usr/share/vim/vim82/syntax/sh.vim` file anywhere a function name
> expression is defined. I have yet to isolate it out and override it in
> my own `.vimrc`. It is a minimal edit.
## Builtins and Utilities ## Builtins and Utilities
A number of builtin and frequently used utility functions have been A number of builtin and frequently used utility functions have been
@ -242,5 +252,5 @@ Displays a summary of usage.
---- ----
*Autogenerated Tue Aug 31 10:00:12 PM EDT 2021* *Autogenerated Tue Aug 31 10:37:57 PM EDT 2021*

42
cmd
View File

@ -35,10 +35,20 @@ This `cmd` inside can then be renamed and finished.
* Name repos containing single bash commands with `cmd-` * Name repos containing single bash commands with `cmd-`
* Name template repos beginning with `template-` * Name template repos beginning with `template-`
* Start command functions with `x_` to be completed * Start command functions with `x.` to be completed
* Name `CONFIG` accessors with `x.` and full path
* Use dot (`.`) pathing in `CONFIG` key names
Think of `x` as in "executable" command. Think of `x` as in "executable" command.
> ⚠️
> Note that all versions of Vim current have a bug that does not allow
> dot (`.`) to be included in the function name even though it is
> explicitly allowed by bash. So you may have to add `.` to your
> `/usr/share/vim/vim82/syntax/sh.vim` file anywhere a function name
> expression is defined. I have yet to isolate it out and override it in
> my own `.vimrc`. It is a minimal edit.
## Builtins and Utilities ## Builtins and Utilities
A number of builtin and frequently used utility functions have been A number of builtin and frequently used utility functions have been
@ -149,7 +159,7 @@ Please mention rwxrob.tv'
HELP[foo]='Foos things.' HELP[foo]='Foos things.'
x_foo () { x.foo () {
_filter "$@" && return $? _filter "$@" && return $?
echo "would foo: $*" echo "would foo: $*"
} }
@ -162,15 +172,15 @@ HELP[bar]='
Bar the things.' Bar the things.'
x_bar() { x.bar() {
_buffer "$@" && return $? _buffer "$@" && return $?
echo "would bar: $*" echo "would bar: $*"
} }
HELP[some.config.setting]='Get and set `some.config.setting`.' HELP[some.config.setting]='Get and set `some.config.setting`.'
x_some.config.setting() { x.some.config.setting() {
x_config some.config.setting "$@" x.config some.config.setting "$@"
} }
############################## BOILERPLATE ########################### ############################## BOILERPLATE ###########################
@ -181,7 +191,7 @@ x_some.config.setting() {
HELP[usage]='Displays a summary of usage.' HELP[usage]='Displays a summary of usage.'
x_usage() { x.usage() {
local -a cmds local -a cmds
for c in "${COMMANDS[@]}"; do for c in "${COMMANDS[@]}"; do
[[ ${c:0:1} =~ _ ]] && continue [[ ${c:0:1} =~ _ ]] && continue
@ -210,7 +220,7 @@ to `$PAGER` (default: more).
Also see `readme` and `usage` commands. Also see `readme` and `usage` commands.
' '
x_help() { x.help() {
local name="${1:-main}" title body local name="${1:-main}" title body
title=$(_help_title "$name") || true title=$(_help_title "$name") || true
if [[ -z "$title" ]]; then if [[ -z "$title" ]]; then
@ -259,7 +269,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 Flavored Markdown suitable for use as a `README.md` file on
GitHub or similar hosting service.' GitHub or similar hosting service.'
x_readme() { x.readme() {
_trim "${HELP[main]}" _trim "${HELP[main]}"
echo echo
while IFS= read -r name; do while IFS= read -r name; do
@ -271,8 +281,8 @@ x_readme() {
echo -e "----\n\n*Autogenerated $(date)*\n" echo -e "----\n\n*Autogenerated $(date)*\n"
} }
# x_json() { _jsonstr "$@"; } # x.json() { _jsonstr "$@"; }
# x_urlencode() { _urlencode "$@"; } # x.urlencode() { _urlencode "$@"; }
# -------------------------- config command -------------------------- # -------------------------- config command --------------------------
@ -343,7 +353,7 @@ Note that this is *not* the same as Java properties and other similar
format. It is designed for ultimate simplicity, efficiency, and format. It is designed for ultimate simplicity, efficiency, and
portability.' portability.'
x_config() { x.config() {
case $1 in case $1 in
dir*) shift; _config_dir "$@"; return $? ;; dir*) shift; _config_dir "$@"; return $? ;;
path) shift; _config_path "$@"; return $? ;; path) shift; _config_path "$@"; return $? ;;
@ -494,8 +504,8 @@ _buffer() {
# `complete -C foo foo` > `source <(foo bloated_completion)` # `complete -C foo foo` > `source <(foo bloated_completion)`
while IFS= read -r line; do while IFS= read -r line; do
[[ $line =~ ^declare\ -f\ x_ ]] || continue [[ $line =~ ^declare\ -f\ x\. ]] || continue
COMMANDS+=( "${line##declare -f x_}" ) COMMANDS+=( "${line##declare -f x.}" )
done < <(declare -F) done < <(declare -F)
mapfile -t COMMANDS < \ mapfile -t COMMANDS < \
<(LC_COLLATE=C sort < <(printf "%s\n" "${COMMANDS[@]}")) <(LC_COLLATE=C sort < <(printf "%s\n" "${COMMANDS[@]}"))
@ -513,7 +523,7 @@ _initialize
for c in "${COMMANDS[@]}"; do for c in "${COMMANDS[@]}"; do
if [[ $c == "$EXE" ]]; then if [[ $c == "$EXE" ]]; then
"x_$EXE" "$@" "x.$EXE" "$@"
exit $? exit $?
fi fi
done done
@ -522,10 +532,10 @@ if [[ -n "$1" ]]; then
declare cmd="$1"; shift declare cmd="$1"; shift
for c in "${COMMANDS[@]}"; do for c in "${COMMANDS[@]}"; do
if [[ $c == "$cmd" ]]; then if [[ $c == "$cmd" ]]; then
"x_$cmd" "$@" "x.$cmd" "$@"
exit $? exit $?
fi fi
done done
fi fi
x_usage "$@" x.usage "$@"