summaryrefslogtreecommitdiff
path: root/backomp
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2023-03-27 01:28:29 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2023-03-27 01:28:29 -0700
commit670b632fd51bfbf4a003daefa4260e9c799c9ff8 (patch)
treebf4ec03d65ced78c61dba6ba85d320a8dfe1a9be /backomp
parent7d120b7939aa5bae68dbb5fc2f877cc8220c6929 (diff)
downloadbackomp-670b632fd51bfbf4a003daefa4260e9c799c9ff8.tar.gz
backomp-670b632fd51bfbf4a003daefa4260e9c799c9ff8.tar.xz
add `$opt=-' syntax for setting a config opt to an empty value
`$opt=' was already being used for resetting an opt to its default value.
Diffstat (limited to 'backomp')
-rwxr-xr-xbackomp19
1 files changed, 13 insertions, 6 deletions
diff --git a/backomp b/backomp
index aba6450..2aa873d 100755
--- a/backomp
+++ b/backomp
@@ -6,8 +6,8 @@ set -e
function flr(n, s) { return int(n / s) * s }
BEGIN {
- split("h d w m", arr)
- for (i = 1; i <= length(arr); ++i) {
+ len = split("h d w m", arr)
+ for (i = 1; i <= len; ++i) {
b = arr[i]
if (!match(retain, "([*0-9]+)" b, md))
@@ -64,8 +64,8 @@ run() {
backup() {
dest_dir="${1}"
src_path="${2}"
- retain="${3:-"*h*d*w*m"}"
- replace="${4:-"h"}"
+ retain="${3}"
+ replace="${4}"
[[ "$((dcount++))" -ne 0 ]] && echo
echo "[${dcount}] [${retain}] ${src_path} => ${dest_dir}"
@@ -96,15 +96,22 @@ backup() {
printf 'kept %s\n' "${keep[@]}"
}
+declare -A def_opts=(
+ ['retain']='*h*d*w*m'
+ ['replace']='h'
+)
declare -A opts
+
while IFS='=' read -r f1 f2; do
[[ -z "${f1}" ]] && continue
if [[ "${f1}" =~ ^\[(.*)]$ ]]; then
base_path="${BASH_REMATCH[1]}"
- opts=()
+ opts="$(declare -p def_opts | sed '1s/[^=]*=//')"
elif [[ "${f1}" == '$'* ]]; then
- opts["${f1:1}"]="${f2}"
+ opt="${f1:1}"
+ [[ "${f2}" == '-' ]] && opts["${opt}"]= ||
+ opts["${opt}"]="${f2:-"${def_opts["${opt}"]}"}"
else
backup "${base_path}/${f1}" "${f2}" \
"${opts['retain']}" "${opts['replace']}"