Move from `x_` to `command_`, closes #2
This commit is contained in:
parent
e1bfbf8e38
commit
6827a1ad55
14
README.md
14
README.md
|
@ -21,17 +21,17 @@ path to this repo to your `PATH`. That way you can keep up with updates.
|
||||||
|
|
||||||
* 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 `command_` to be completed
|
||||||
* Start command functions with `x__` to not be completed
|
* Start command functions with `command__` to not be completed
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```
|
```
|
||||||
cmd
|
command
|
||||||
cmd usage
|
command usage
|
||||||
cmd help [<cmd>]
|
command help [<cmd>]
|
||||||
cmd foo [<arg>]
|
command foo [<arg>]
|
||||||
cmd bar [<arg>]
|
command bar [<arg>]
|
||||||
```
|
```
|
||||||
|
|
||||||
## Commands
|
## Commands
|
||||||
|
|
|
@ -32,26 +32,26 @@ completion, but still want them to be avaiable, just hidden.
|
||||||
|
|
||||||
help[foo]='The `foo` command foos.'
|
help[foo]='The `foo` command foos.'
|
||||||
|
|
||||||
x_foo() {
|
command_foo() {
|
||||||
_filter "$@" && return $?
|
_filter "$@" && return $?
|
||||||
echo "would foo: $*"
|
echo "would foo: $*"
|
||||||
}
|
}
|
||||||
|
|
||||||
help[bar]='The `bar` command bars.'
|
help[bar]='The `bar` command bars.'
|
||||||
|
|
||||||
x_bar() {
|
command_bar() {
|
||||||
_buffer "$@" && return $?
|
_buffer "$@" && return $?
|
||||||
echo "would bar: $*"
|
echo "would bar: $*"
|
||||||
}
|
}
|
||||||
|
|
||||||
x__hidden() {
|
command__hidden() {
|
||||||
_filter "$@" && return $?
|
_filter "$@" && return $?
|
||||||
echo "would run _hidden: $*"
|
echo "would run _hidden: $*"
|
||||||
}
|
}
|
||||||
|
|
||||||
help[usage]='The `usage` command displays a summary of usage.'
|
help[usage]='The `usage` command displays a summary of usage.'
|
||||||
|
|
||||||
x_usage() {
|
command_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
|
||||||
|
@ -70,13 +70,13 @@ is written in CommonMark (Markdown) and will displayed as Web page if
|
||||||
`pandoc` and `$HELP_BROWSER` are detected, otherwise, just the Markdown is
|
`pandoc` and `$HELP_BROWSER` are detected, otherwise, just the Markdown is
|
||||||
sent to `$PAGER` (default: more).'
|
sent to `$PAGER` (default: more).'
|
||||||
|
|
||||||
x_help() {
|
command_help() {
|
||||||
local name="$1"
|
local name="$1"
|
||||||
if [[ -z "$name" ]];then
|
if [[ -z "$name" ]];then
|
||||||
for c in "${COMMANDS[@]}";do
|
for c in "${COMMANDS[@]}";do
|
||||||
x_help "$c" buildonly
|
command_help "$c" buildonly
|
||||||
done
|
done
|
||||||
x_help main
|
command_help main
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
local title="$EXE $name"
|
local title="$EXE $name"
|
||||||
|
@ -113,8 +113,8 @@ _buffer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
while IFS= read -r line; do
|
while IFS= read -r line; do
|
||||||
[[ $line =~ ^declare\ -f\ x_ ]] || continue
|
[[ $line =~ ^declare\ -f\ command_ ]] || continue
|
||||||
COMMANDS+=( "${line##declare -f x_}" )
|
COMMANDS+=( "${line##declare -f command_}" )
|
||||||
done < <(declare -F)
|
done < <(declare -F)
|
||||||
|
|
||||||
if [[ -n $COMP_LINE ]]; then
|
if [[ -n $COMP_LINE ]]; then
|
||||||
|
@ -127,7 +127,7 @@ fi
|
||||||
|
|
||||||
for c in "${COMMANDS[@]}"; do
|
for c in "${COMMANDS[@]}"; do
|
||||||
if [[ $c == "$EXE" ]]; then
|
if [[ $c == "$EXE" ]]; then
|
||||||
"x_$EXE" "$@"
|
"command_$EXE" "$@"
|
||||||
exit $?
|
exit $?
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
@ -136,10 +136,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" "$@"
|
"command_$cmd" "$@"
|
||||||
exit $?
|
exit $?
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
x_usage "$@"
|
command_usage "$@"
|
Loading…
Reference in New Issue