Add `value`, `keys`, `delete` to `config`
This commit is contained in:
parent
4228dcc7b9
commit
dae44446b9
21
README.md
21
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.)
|
||||
|
||||
Be sure to check out the builtin and utility functions. Some of these
|
||||
|
||||
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
|
||||
|
||||
* Name repos containing single bash commands with `cmd-`
|
||||
|
@ -87,9 +90,12 @@ cmd config
|
|||
cmd config KEY
|
||||
cmd config KEY VALUE
|
||||
cmd config KEY ""
|
||||
cmd config dir
|
||||
cmd config keys
|
||||
cmd config val[ues]
|
||||
cmd config dir[ectory]
|
||||
cmd config path [file]
|
||||
cmd config edit [file]
|
||||
cmd config del[ete]
|
||||
```
|
||||
|
||||
The `config` command is for reading, writing, and displaying standard
|
||||
|
@ -104,9 +110,12 @@ settings.
|
|||
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:
|
||||
|
||||
* `dir` full path to config directory
|
||||
* `dir*` full path to config directory
|
||||
* `path` full path to specific config file (default: `values`)
|
||||
* `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
|
||||
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 or similar hosting service.
|
||||
|
||||
## The `some.config.setting` Command
|
||||
|
||||
Get and set `some.config.setting`.
|
||||
|
||||
## The `usage` Command
|
||||
|
||||
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*
|
||||
|
||||
|
|
40
cmd
40
cmd
|
@ -114,6 +114,13 @@ command_bar() {
|
|||
_buffer "$@" && return $?
|
||||
echo "would bar: $*"
|
||||
}
|
||||
|
||||
HELP[some.config.setting]='Get and set `some.config.setting`.'
|
||||
|
||||
command_some.config.setting() {
|
||||
command_config some.config.setting "$@"
|
||||
}
|
||||
|
||||
command__hidden() {
|
||||
_filter "$@" && return $?
|
||||
echo "would run _hidden: $*"
|
||||
|
@ -226,9 +233,12 @@ HELP[config]='
|
|||
'"$EXE"' config KEY
|
||||
'"$EXE"' config KEY VALUE
|
||||
'"$EXE"' config KEY ""
|
||||
'"$EXE"' config dir
|
||||
'"$EXE"' config keys
|
||||
'"$EXE"' config val[ues]
|
||||
'"$EXE"' config dir[ectory]
|
||||
'"$EXE"' config path [file]
|
||||
'"$EXE"' config edit [file]
|
||||
'"$EXE"' config del[ete]
|
||||
```
|
||||
|
||||
The `config` command is for reading, writing, and displaying standard
|
||||
|
@ -243,9 +253,12 @@ settings.
|
|||
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:
|
||||
|
||||
* `dir` full path to config directory
|
||||
* `dir*` full path to config directory
|
||||
* `path` full path to specific config file (default: `values`)
|
||||
* `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
|
||||
be combined into the VALUE and written to a `values` file in the
|
||||
|
@ -282,9 +295,12 @@ portability.'
|
|||
|
||||
command_config() {
|
||||
case $1 in
|
||||
dir) _config_dir; return $? ;;
|
||||
path) _config_path; return $? ;;
|
||||
edit) _config_edit; return $? ;;
|
||||
dir*) shift; _config_dir "$@"; return $? ;;
|
||||
path) shift; _config_path "$@"; return $? ;;
|
||||
edit) shift; _config_edit "$@"; return $? ;;
|
||||
del*) shift; _config_del "$@"; return $? ;;
|
||||
keys) shift; _config_keys "$@"; return $? ;;
|
||||
val*) shift; _config_vals "$@"; return $? ;;
|
||||
esac
|
||||
case $# in
|
||||
0) _config_dump ;;
|
||||
|
@ -298,6 +314,20 @@ _config_edit() {
|
|||
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() {
|
||||
local dir="$HOME/.config/$EXE"
|
||||
[[ -n "$XDG_CONFIG_HOME" ]] && dir="$XDG_CONFIG_HOME/$EXE"
|
||||
|
|
Loading…
Reference in New Issue