Add `value`, `keys`, `delete` to `config`
This commit is contained in:
parent
4228dcc7b9
commit
dae44446b9
23
README.md
23
README.md
|
@ -19,9 +19,12 @@ tab completion, but will still be there. The `readme` command (which
|
||||||
generates this `README.md` file is a good candidate for this.)
|
generates this `README.md` file is a good candidate for this.)
|
||||||
|
|
||||||
Be sure to check out the builtin and utility functions. Some of these
|
Be sure to check out the builtin and utility functions. Some of these
|
||||||
|
|
||||||
can be removed as well if you really want.
|
can be removed as well if you really want.
|
||||||
|
|
||||||
|
The `_initialize` function is meant to put initialization code at the
|
||||||
|
beginning of the script to be found easily even though it is called at
|
||||||
|
the bottom of the script (as bash requires).
|
||||||
|
|
||||||
## Naming Conventions
|
## Naming Conventions
|
||||||
|
|
||||||
* Name repos containing single bash commands with `cmd-`
|
* Name repos containing single bash commands with `cmd-`
|
||||||
|
@ -87,9 +90,12 @@ cmd config
|
||||||
cmd config KEY
|
cmd config KEY
|
||||||
cmd config KEY VALUE
|
cmd config KEY VALUE
|
||||||
cmd config KEY ""
|
cmd config KEY ""
|
||||||
cmd config dir
|
cmd config keys
|
||||||
|
cmd config val[ues]
|
||||||
|
cmd config dir[ectory]
|
||||||
cmd config path [file]
|
cmd config path [file]
|
||||||
cmd config edit [file]
|
cmd config edit [file]
|
||||||
|
cmd config del[ete]
|
||||||
```
|
```
|
||||||
|
|
||||||
The `config` command is for reading, writing, and displaying standard
|
The `config` command is for reading, writing, and displaying standard
|
||||||
|
@ -99,14 +105,17 @@ a property.
|
||||||
### Arguments
|
### Arguments
|
||||||
|
|
||||||
With no arguments outputs all the currently cached configuration
|
With no arguments outputs all the currently cached configuration
|
||||||
settings.
|
settings.
|
||||||
|
|
||||||
With a single KEY argument fetches the value for that key and outputs
|
With a single KEY argument fetches the value for that key and outputs
|
||||||
it unless it is one of the following special (reserved) key names:
|
it unless it is one of the following special (reserved) key names:
|
||||||
|
|
||||||
* `dir` full path to config directory
|
* `dir*` full path to config directory
|
||||||
* `path` full path to specific config file (default: `values`)
|
* `path` full path to specific config file (default: `values`)
|
||||||
* `edit` opens config file in editor (default: `editor` or `$EDITOR)
|
* `edit` opens config file in editor (default: `editor` or `$EDITOR)
|
||||||
|
* `keys` output the configuration keys, one per line
|
||||||
|
* `val*` output the configuration values, one per line
|
||||||
|
* `del*` if key argument then delete a specific key, otherwise prompt
|
||||||
|
|
||||||
With more than one argument the remaining arguments after the KEY will
|
With more than one argument the remaining arguments after the KEY will
|
||||||
be combined into the VALUE and written to a `values` file in the
|
be combined into the VALUE and written to a `values` file in the
|
||||||
|
@ -183,11 +192,15 @@ 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.
|
||||||
|
|
||||||
|
## The `some.config.setting` Command
|
||||||
|
|
||||||
|
Get and set `some.config.setting`.
|
||||||
|
|
||||||
## The `usage` Command
|
## The `usage` Command
|
||||||
|
|
||||||
Displays a summary of usage.
|
Displays a summary of usage.
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
*Autogenerated Fri Aug 27 09:16:17 AM EDT 2021*
|
*Autogenerated Sun Aug 29 12:18:52 PM EDT 2021*
|
||||||
|
|
||||||
|
|
42
cmd
42
cmd
|
@ -114,6 +114,13 @@ command_bar() {
|
||||||
_buffer "$@" && return $?
|
_buffer "$@" && return $?
|
||||||
echo "would bar: $*"
|
echo "would bar: $*"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HELP[some.config.setting]='Get and set `some.config.setting`.'
|
||||||
|
|
||||||
|
command_some.config.setting() {
|
||||||
|
command_config some.config.setting "$@"
|
||||||
|
}
|
||||||
|
|
||||||
command__hidden() {
|
command__hidden() {
|
||||||
_filter "$@" && return $?
|
_filter "$@" && return $?
|
||||||
echo "would run _hidden: $*"
|
echo "would run _hidden: $*"
|
||||||
|
@ -226,9 +233,12 @@ HELP[config]='
|
||||||
'"$EXE"' config KEY
|
'"$EXE"' config KEY
|
||||||
'"$EXE"' config KEY VALUE
|
'"$EXE"' config KEY VALUE
|
||||||
'"$EXE"' config KEY ""
|
'"$EXE"' config KEY ""
|
||||||
'"$EXE"' config dir
|
'"$EXE"' config keys
|
||||||
|
'"$EXE"' config val[ues]
|
||||||
|
'"$EXE"' config dir[ectory]
|
||||||
'"$EXE"' config path [file]
|
'"$EXE"' config path [file]
|
||||||
'"$EXE"' config edit [file]
|
'"$EXE"' config edit [file]
|
||||||
|
'"$EXE"' config del[ete]
|
||||||
```
|
```
|
||||||
|
|
||||||
The `config` command is for reading, writing, and displaying standard
|
The `config` command is for reading, writing, and displaying standard
|
||||||
|
@ -238,14 +248,17 @@ a property.
|
||||||
### Arguments
|
### Arguments
|
||||||
|
|
||||||
With no arguments outputs all the currently cached configuration
|
With no arguments outputs all the currently cached configuration
|
||||||
settings.
|
settings.
|
||||||
|
|
||||||
With a single KEY argument fetches the value for that key and outputs
|
With a single KEY argument fetches the value for that key and outputs
|
||||||
it unless it is one of the following special (reserved) key names:
|
it unless it is one of the following special (reserved) key names:
|
||||||
|
|
||||||
* `dir` full path to config directory
|
* `dir*` full path to config directory
|
||||||
* `path` full path to specific config file (default: `values`)
|
* `path` full path to specific config file (default: `values`)
|
||||||
* `edit` opens config file in editor (default: `editor` or `$EDITOR)
|
* `edit` opens config file in editor (default: `editor` or `$EDITOR)
|
||||||
|
* `keys` output the configuration keys, one per line
|
||||||
|
* `val*` output the configuration values, one per line
|
||||||
|
* `del*` if key argument then delete a specific key, otherwise prompt
|
||||||
|
|
||||||
With more than one argument the remaining arguments after the KEY will
|
With more than one argument the remaining arguments after the KEY will
|
||||||
be combined into the VALUE and written to a `values` file in the
|
be combined into the VALUE and written to a `values` file in the
|
||||||
|
@ -282,9 +295,12 @@ portability.'
|
||||||
|
|
||||||
command_config() {
|
command_config() {
|
||||||
case $1 in
|
case $1 in
|
||||||
dir) _config_dir; return $? ;;
|
dir*) shift; _config_dir "$@"; return $? ;;
|
||||||
path) _config_path; return $? ;;
|
path) shift; _config_path "$@"; return $? ;;
|
||||||
edit) _config_edit; return $? ;;
|
edit) shift; _config_edit "$@"; return $? ;;
|
||||||
|
del*) shift; _config_del "$@"; return $? ;;
|
||||||
|
keys) shift; _config_keys "$@"; return $? ;;
|
||||||
|
val*) shift; _config_vals "$@"; return $? ;;
|
||||||
esac
|
esac
|
||||||
case $# in
|
case $# in
|
||||||
0) _config_dump ;;
|
0) _config_dump ;;
|
||||||
|
@ -298,6 +314,20 @@ _config_edit() {
|
||||||
exec "${CONFIG[editor]}" "$(_config_path "${1:-values}")"
|
exec "${CONFIG[editor]}" "$(_config_path "${1:-values}")"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_config_del() {
|
||||||
|
if [[ -z "$1" ]];then
|
||||||
|
select key in "${!CONFIG[@]}"; do
|
||||||
|
_config_del "$key"
|
||||||
|
return $?
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
_config_set "$1" ''
|
||||||
|
}
|
||||||
|
|
||||||
|
_config_keys() { printf "%s\n" "${!CONFIG[@]}"; }
|
||||||
|
|
||||||
|
_config_vals() { printf "%s\n" "${CONFIG[@]}"; }
|
||||||
|
|
||||||
_config_dir() {
|
_config_dir() {
|
||||||
local dir="$HOME/.config/$EXE"
|
local dir="$HOME/.config/$EXE"
|
||||||
[[ -n "$XDG_CONFIG_HOME" ]] && dir="$XDG_CONFIG_HOME/$EXE"
|
[[ -n "$XDG_CONFIG_HOME" ]] && dir="$XDG_CONFIG_HOME/$EXE"
|
||||||
|
|
Loading…
Reference in New Issue